单击 JButton 时是否有禁用蓝色框的方法?

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

我认为这不是必需的,但这是我的按钮的代码

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

按钮形式很好。带有橙色文本的黑色背景。 但是当我点击它时,按钮会变成浅蓝色,直到我松开鼠标按钮。

有没有方法说:button.setHighlight(false);

或类似的东西,这样即使我单击按钮,它也会保持其颜色或更改为我选择的颜色,我将其设置为 Color.BLACK?

JButton 的背景颜色在look-and-feel. You can alter the color via class UIManager 中设置。当您在 JButton 上按下鼠标按钮时,表示 JButton 已布防。这是设置 JButton 武装时颜色的代码。

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

当鼠标指针悬停在 JButton 上时按下鼠标按钮,这将使 JButton 背景变为橙色。