jToggleButton isSelected and setBackground is not working as expected

100 Views Asked by At

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.

1

There are 1 best solutions below

2
Nillohit Banerjee On

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