0

I am trying to make it so that the button will change color whenever it is selected. I tried using an if statement to see if the button is selected, and if it is, it will set it to red. However it doesn't work.

if(jToggleButton1.isSelected()) {
                    jToggleButton1.setBackground(Color.RED);
                }

If anyone can describe to me how to make me work that would be much appreciated.

dev1998
  • 882
  • 7
  • 17
Al-x
  • 19
  • 7

1 Answers1

0

you have to rerender your button . Then only you can see this is red.

  • Can you explain to me how I can re-render a button? I am still trying to learn Java and I'm not quite sure as to how I can do that. – Al-x Jan 17 '18 at 18:46
  • hopefully https://stackoverflow.com/questions/12865803/how-do-i-refresh-a-gui-in-java this helps – Nillohit Banerjee Jan 17 '18 at 18:54