How do I change the color of a JButton if I am using JGoodies WindowsLookAndFeel
? After changing the color the button should still have some visual indication when it is clicked; the color gradient and click animation do not have to be the same as in JGoodies.
Using setBackground()
and setForeground()
only changes the color of the button outline and the button text:
import com.jgoodies.looks.windows.WindowsLookAndFeel;
...
public class Test {
public static void main(String[] args) throws UnsupportedLookAndFeelException {
UIManager.setLookAndFeel(new WindowsLookAndFeel());
JFrame frame = new JFrame();
frame.setSize(50, 100);
JButton button = new JButton("Button");
button.setBackground(Color.GREEN);
button.setForeground(Color.RED);
button.setOpaque(true);
frame.add(button);
frame.setVisible(true);
}
}
I would like to set the color for the whole area of the button not just the outline. (This happens if the WindowsLookAndFeel
is not used.)
I have also tried changing the colors in com.jgoodies.looks.windows.WindowsBorders#getButtonBorder()
but this does not seem to have any effect.
Try adding call to setContentAreaFilled:
button.setContentAreaFilled(false); //must be before setOpaque
button.setOpaque(true);
or you can override JButton and paint: Change JButton gradient color, but only for one button, not all
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With