'I don't want to change color of JButton when pressed

Color newColor = new Color(197,222,90);
JButton newButton;
newButton = new JButton(icon);
newButton.setBacgroundColor(newColor);

When it is pressed it changes color. How can I keep it from changing color? I have multiple buttons, so if there is solution in one or two rows please help me, and keep in mind that I'm beginner, writing some huge classes won't help me, because I have multiple buttons with different names to be affected with this.

EDIT: Solution in one line is:

 UIManager.put("Button.select", newColor);

But it changes all button colors but I need another to have different a color.

EDIT2: After some research I figured out there isn't an easy solution (but it should be). How I see it I have 2 solutions, 1. is to break buttons to separate classes and set UIManager for them, and second is to make custom buttons. It is just too much work for button.



Solution 1:[1]

If the OP is referring to the temporary change of background colour on a button with an icon at the moment the mouse is pressed, the following statement does the trick:

button.setContentAreaFilled(false);

"If you wish to have a transparent button, such as an icon only button, for example, then you should set this to false."

This took me a long time to figure out. It seems to be a little known technique, perhaps since its name gives little clue as to its effect.

Solution 2:[2]

With only first lane we can still see that it is clicked. You need to combine those two:

button1.setContentAreaFilled(false);
button1.setEnabled(false);

and if you don't wanna in grey color you put another button under him.

panelname.add(button1,+5,+5); \\(first not clicable, not visible button, notice +5) 

panelname.add(button2,-5,-5); \(-5,-5 means it is 5 points under panel)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2