I have a JButton with an icon on it. I want the background color of the JButton to be the same as the icon.
The following code works fine in the standard look-and-feel :
button.setBackground(new Color(212,208,199));
But when I change my look-and-feel to Nimbus, then the background color of the JButton is much lighter.
The JButton still changes its background color when I change the color in button.setBackground(), but I have no idea to what color I need in Nimbus to get the same color as the background color of the JButton. Of course I could try to find the color by sight by trying all values, but there should be a simpler way.
I also tried changing the background color via the following code, but with the same result :
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
defaults.put("Button.background",new Color(212,208,199));
How can I change the background color of my JButton in Nimbus, so that it merges with the background color of the containing icon ?
Below are some pictures of the button with default LaF, nimbus LaF (same code), and nimbus LaF (red color) :
Default LaF, using button.setBackground(new Color(212,208,199))
:
Nimbus LaF, using button.setBackground(new Color(212,208,199))
:
Nimbus LaF, using button.setBackground(Color.red)
: