I want the button on click it never change the background color, by default the color will change to light blue grey color.
So this is my code
JButton b = new JButton();
b.setBackground(SystemColor.control);
I want the button when on click it will never change the background color.
The painting of the button depends on LAF. You can do one of the following:
Disadvantages: complex, breaks LAF.
JButtonand implementpaintComponent().Disadvantages: You will need to paint button’s label yourself.
setContentAreaFilled(false)and then add the button in the opaque panel with the needed background color.Advantages: button is unchanged, LAF isn’t broken.
Disadvantages: you need to create a panel for each button, and adjust it to fit the button exactly, which can be quite difficult, depending on the layout.