JButton Background at Nimbus LAF

I am using Nimbus LAF and I want to change the background of a simple JButton.

JButton jbutton = new JButton("test");
jbutton.setBackground(Color.BLACK);

But this will not work when I change the look and feel that it works, but it does not work in Nimbus.

How can i do this?

Thank you for your help.

+1
source share
1 answer

Nimbus uses Painter to draw different styles. By default, a button has a gradient of more than one color. See "Button": Nimbus Default List

You can write your own Painter and override the default value. Or you override the background color using the "Button.background" key and use "Default".

UIDefaults overrides = new UIDefaults();
overrides.put("Button.background", Color.RED);
jbutton.putClientProperty("Nimbus.Overrides", overrides);
jbutton.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
SwingUtilities.updateComponentTreeUI(jbutton);

, , :

UIDefaults defaults = UIManager.getLookAndFeelDefaults();
defaults.put("Button.background",  Color.RED);

Btw. JButton Nimbus "nimbusBase", :

UIDefaults defaults = UIManager.getLookAndFeelDefaults();
defaults.put( "nimbusBase", Color.RED );

, nimbus defalut-blue , .

Nimbus, Nimbus : http://aephyr.googlecode.com/svn/trunk p >

+6

All Articles