2

In Java Swing application, I am using nimbus look and feel. I try to override JPanel background color (enabled or disabled) without success.

Doc oracle, Nimbus Defaults -> Search "Panel.background".

I instantiate the JPanel like this:

JPanel panel = new JPanel() {

        private static final long serialVersionUID = 1L;

        @Override
        public void updateUI() {

            if ("Nimbus".equals(UIManager.getLookAndFeel().getName())) {
                UIDefaults map = new UIDefaults();
                map.put("Panel.background", Color.yellow); // Works fine :)
                map.put("Panel.disabled", Color.red); // Don't work :'(
                putClientProperty("Nimbus.Overrides", map);
            }
            super.updateUI();
        }
    };

I am trying too:

map.put("Panel[Disabled].background", Color.blue); // Don't work too :'(
Stéphane Millien
  • 3,238
  • 22
  • 36

1 Answers1

3

Finally, I have found my mistake.

map.put("Panel.background", new ColorUIResource(Color.yellow));
map.put("Panel[Disabled].background", new ColorUIResource(Color.red));

Missing "new ColorUIResource". This works like a charm.

Stéphane Millien
  • 3,238
  • 22
  • 36