SystemColor in Linux - what's wrong?

  • Thread starter Alexandr Molochnikov
  • Start date
A

Alexandr Molochnikov

SystemColor.textHighlight is supposed to be the color of the "background of
selected items, such as in menus, comboboxes, and text" - quoted from
SystemColor API docs. And under Windows, it does what the manual says.

However, in Linux SystemColor.textHighlight is black (r=0,g=0,b=0). The menu
background, for comparison, is blueish (r=153,g=153,b=204).

Does anyone know why this happens? I attached a small program that
demonstrates the problem; if someone could run it under Linux and tell me if
my observations are correct, this will remove my setup from the list of
suspects.

I use Java 1.4.1_03 under Linux Red Hat 9.

On a related note, how do the UIDefaults map onto the SystemColor? E.g.
which property the value for SystemColor.textHighlight comes from?

Thank you for any clues.

Alex Molochnikov
Gestalt Corporation


Here is the demo program:

import java.awt.*;
import java.util.*;
import javax.swing.*;

public class Controller
{
private JFrame frame;
private Container contentPane;
private Font textFont;

public static void main(String args[])
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }
catch (Exception exc) { System.out.println("Error loading L&F: " + exc); }
new Controller();
}

public Controller()
{
frame = new JFrame("Test");
textFont = new Font("SansSerif",Font.PLAIN,12);
frame.addNotify();
frame.pack();
contentPane = frame.getContentPane();
contentPane.setLayout(null);
frame.setSize(400, 265);
frame.validate();
createMenu();
createViews();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

public void createViews()
{
JLabel label1 = new JLabel("textHighlight");
label1.setFont(textFont);
label1.setBorder(BorderFactory.createEtchedBorder());
label1.setSize(label1.getPreferredSize());
label1.setBackground(SystemColor.textHighlight);
label1.setLocation(10, 10);
label1.setOpaque(true);
label1.setToolTipText("Background: SystemColor.textHighlight");
contentPane.add(label1);
JLabel caption = new JLabel("Background: SystemColor.textHighlight");
caption.setFont(textFont);
caption.setSize(caption.getPreferredSize());
caption.setLocation(150, 10);
contentPane.add(caption);

JLabel label2 = new JLabel("textHighlightText");
label2.setFont(textFont);
label2.setBorder(BorderFactory.createEtchedBorder());
label2.setSize(label2.getPreferredSize());
label2.setBackground(SystemColor.textHighlightText);
label2.setLocation(10, 40);
label2.setOpaque(true);
label2.setToolTipText("Background: SystemColor.textHighlightText");
contentPane.add(label2);
caption = new JLabel("Background: SystemColor.textHighlightText");
caption.setFont(textFont);
caption.setSize(caption.getPreferredSize());
caption.setLocation(150, 40);
contentPane.add(caption);

JLabel label3 = new JLabel("textText");
label3.setFont(textFont);
label3.setBorder(BorderFactory.createEtchedBorder());
label3.setSize(label3.getPreferredSize());
label3.setBackground(SystemColor.textText);
label3.setLocation(10, 70);
label3.setOpaque(true);
label3.setToolTipText("Background: SystemColor.textText");
contentPane.add(label3);
caption = new JLabel("Background: SystemColor.textText");
caption.setFont(textFont);
caption.setSize(caption.getPreferredSize());
caption.setLocation(150, 70);
contentPane.add(caption);

JLabel label4 = new JLabel("control");
label4.setFont(textFont);
label4.setBorder(BorderFactory.createEtchedBorder());
label4.setSize(label4.getPreferredSize());
label4.setBackground(SystemColor.control);
label4.setLocation(10, 100);
label4.setOpaque(true);
label4.setToolTipText("Background: SystemColor.control");
contentPane.add(label4);
caption = new JLabel("Background: SystemColor.control");
caption.setFont(textFont);
caption.setSize(caption.getPreferredSize());
caption.setLocation(150, 100);
contentPane.add(caption);

JLabel label5 = new JLabel("controlText");
label5.setFont(textFont);
label5.setBorder(BorderFactory.createEtchedBorder());
label5.setSize(label5.getPreferredSize());
label5.setBackground(SystemColor.controlText);
label5.setLocation(10, 130);
label5.setOpaque(true);
label5.setToolTipText("Background: SystemColor.controlText");
contentPane.add(label5);
caption = new JLabel("Background: SystemColor.controlText");
caption.setFont(textFont);
caption.setSize(caption.getPreferredSize());
caption.setLocation(150, 130);
contentPane.add(caption);

JLabel label6 = new JLabel("textInactiveText");
label6.setFont(textFont);
label6.setBorder(BorderFactory.createEtchedBorder());
label6.setSize(label6.getPreferredSize());
label6.setBackground(SystemColor.textInactiveText);
label6.setLocation(10, 160);
label6.setOpaque(true);
label6.setToolTipText("Background: SystemColor.textInactiveText");
contentPane.add(label6);
caption = new JLabel("Background: SystemColor.textInactiveText");
caption.setFont(textFont);
caption.setSize(caption.getPreferredSize());
caption.setLocation(150, 160);
contentPane.add(caption);

JLabel label7 = new JLabel("inactiveCaption");
label7.setFont(textFont);
label7.setBorder(BorderFactory.createEtchedBorder());
label7.setSize(label7.getPreferredSize());
label7.setBackground(SystemColor.inactiveCaption);
label7.setLocation(10, 190);
label7.setOpaque(true);
label7.setToolTipText("Background: SystemColor.inactiveCaption");
contentPane.add(label7);
caption = new JLabel("Background: SystemColor.inactiveCaption");
caption.setFont(textFont);
caption.setSize(caption.getPreferredSize());
caption.setLocation(150, 190);
contentPane.add(caption);
}

protected void createMenu()
{
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
/*
** Create submenu
*/
JMenu menu = new JMenu("Test");
menuBar.add(menu);
JMenuItem item1 = new JMenuItem("Item 1");
menu.add(item1);
JMenuItem item2 = new JMenuItem("Item 2");
menu.add(item2);
JMenuItem item3 = new JMenuItem("Item 3");
menu.add(item3);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top