1

I am using netbeans to create a desktop application, and I am trying to change the background color of a JButton, btn1 using the code

btn1.setBackground(Color.Red)

But this does not work. Instead of changing the fill color of the button, only the border color is changed. How can I change the background fill?

Thanks

mKorbel
  • 109,525
  • 20
  • 134
  • 319
jpo
  • 3,959
  • 20
  • 59
  • 102

1 Answers1

4

See this related question and answer.

In particular, you can use setForeground() to change the color of a button's text, but the corresponding setBackground() doesn't read well on some platforms. Using a Border is one alternative; a colored panel, shown below, is another.

You can also try calling setOpaque(true) on your button.

Community
  • 1
  • 1
lrAndroid
  • 2,834
  • 18
  • 27