2

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:

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);
        }
    }
}
Community
  • 1
  • 1
Emad
  • 769
  • 9
  • 21
  • 2
    Consider creating and posting your [minimal, compilable and runnable example](http://stackoverflow.com/help/mcve). – Hovercraft Full Of Eels Feb 08 '14 at 14:51
  • Are you sure you're setting the look and feel before creating the frame and combo box? In the earlier revision of the question you had it round the other way. – Boann Feb 08 '14 at 15:07
  • Yes. it's in the question. – Emad Feb 08 '14 at 15:13
  • http://stackoverflow.com/questions/10723115/changing-a-color-chooser-buttons-background-color-in-java and try this small app: http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/ – 1ac0 Feb 08 '14 at 15:17
  • I don't see reason for this question, read JComboBox and rendereing concept in JComboBox, JList or JTable (very similair concept), logics is different for editable and no_editable JComboBox – mKorbel Feb 08 '14 at 20:15

1 Answers1

0

I've just ran your code, and it works fine on my Windows 7 system - 64 bit. so I wonder, what might be wrong in your windows 7 system.

I would try to reinstall Java on that machine !

David Gidony
  • 1,243
  • 3
  • 16
  • 31