Search code examples
javaswingjbutton

How to set the button color of a JButton (not background color)


I have a JButton that I would like to change the background color of to white. When using the Metal Look And Feel, I achieve the desired effect with setBackground:

Metal look-and-feel-styled JButton with a white background

Unfortunately, the concept of "background color" is different when using the Windows LAF; the background color is the color drawn around the button:

Windows look-and-feel-styled JButton with a white background

I would like to use the Windows LAF, but allow the button color of this JButton to be changed to white. How do I do this?


Solution

  • You'll have to decide if it's worth the effort, but you can always create youe own ButtonUI, as shown in this example due to @mKorbel.