Home > Enterprise >  Is there a method to disable the blue box when I click a JButton?
Is there a method to disable the blue box when I click a JButton?

Time:09-17

I don't think it's required but here is the code for my button

JButton button = new JButton(text);
button.setFocusable(false);
button.setBackground(Color.BLACK);
button.setForeground(Color.ORANGE);
button.setBorderPainted(false);

The button forms just fine. A black background with orange text. But when I click it, the button turns light-blue until I release the mouse button.

Is there a method say: button.setHighlight(false);

or something like that so that even when I click the button, it will keep its color or change to a color of my choice which I will just set to Color.BLACK?

CodePudding user response:

The background color of JButton is set in the look-and-feel. You can alter the color via class UIManager. When you press the mouse button on the JButton, the JButton is said to be armed. Here is the code that sets the color of the JButton when it is armed.

UIManager.put("Button.select", Color.orange);

This will make the JButton background orange when you press the mouse button when the mouse pointer is over the JButton.

  • Related