I am trying to change background color of a JComboBox
to red using setBackground
. It works in windows XP, but it doesn't work in windows 7. I Try all the following solutions:
- Why does setBackground to JButton does not work?
- How to set background color of a button in Java GUI?
here is my code:
public class HelloWorld
{
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
JFrame hello = new JFrame("Hello World");
JComboBox combo = new JComboBox();
combo.setBackground(Color.red);
combo.setOpaque(true);
hello.add(combo);
hello.pack();
hello.setVisible(true);
}
catch (ClassNotFoundException ex)
{
Logger.getLogger(HelloWorld.class.getName()).log(Level.SEVERE, null,
ex);
}
}
}