问题
I have a JPanel with a JButton, JTextField and a JTable, and the TAB key traverses these components as expected with a little black box drawn around the component (or cell in case of the JTable) that has focus. How can I change the color of the black-box focus indicator?
回答1:
The selection appearance is under the control of each component's UI delegate, discussed in How to Set the Look and Feel.
As a concrete example, on certain L&Fs, you can override the default value when your program starts up:
UIManager.put("Button.focus", Color.red);
来源:https://stackoverflow.com/questions/6877603/change-the-color-of-the-java-swing-component-focus-indicator