I have the following simple code:
btn = new JButton();
btn.setBackground(backgroundColor)
I worked when I used:
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
But it stopped to work after I have commented the above line. Does anybody know why it can happen and how I can set a background color to a button without the usage of an explicit Look and Feel?
ADDED
It seems to me that I need to use getBackground
. But I do not know how.
UIManager
line like that: hardcoding the PLAF class name means your code will not run when that PLAF is not available (for example on non-Windows JDKs or on newer Windows JDK that might stop shipping that specific class).UIManager.getSystemLookAndFeelClassName()
might be what you're after. – Ananna