Changing the background color of a button

How to change the background color of a button when a button is pressed?
In my case, when a button is pressed, I will toggle a boolean variable and depending upon the bool variable the background color needs to be changed

My program in a swingToolbarService program.

Pretty sure the style guide dictates what you’re allowed to have for background colors, but hey. If you can get it approved, more power to ya. Add a mouse listener to the button and utilize the “mouseClicked()” method. MouseListener (Java Platform SE 7 )