Skip to main content

how to change button color

2 replies [Last post]
Joined: 2009-04-21

Hi, I am new to java swing and I need a little bit help.

In my application I want confirm and cancel button and I want to have theese buttons colored. One green and other red. But I do not know how to do it. When I change the background color, the color is changed behind the button and the button is stil grey and when I changed foreground it changes the color of the button label.

But whatever I have done I was not able to change the button color from the default grey. Please can you advice me how to do it?



Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2004-04-27

IFF you wanna really do it, just overwrite the paint method, something like

public void paint(Graphics g) {
Rectangle mu = g.getClipBounds();
g.fillRect(mu.x, mu.y, mu.width, mu.height);

keep in mind, you are changing the default behaviour of the Style-Guides!!!

Joined: 2005-08-27

To give a correct answer we need to know which operating system and which LAF you
are using.
For standard Windows, I don't think it is possible with base Swing.
You may be able to use Swingx JXButton which is painter enabled.
See or