5

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 Answer 1

4

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);
4
  • Thanks, that got me a step forward. What I'm trying to figure out is why some JTables in a large application have the focus indicator and some don't. I used: UIManager.put("Table.focusCellHighlightBorder",new BorderUIResource(new LineBorder(new Color(255,0,0))); And those JTables with focus indicators changed to red but I still don't see the focus indicator on all JTables. Any idea why a cell in a JTable wouldn't show the focus indicator?
    – splatek
    Jul 29, 2011 at 20:18
  • 1
    @splatek but that topic for new question, with your code ... java2s.com/Code/Java/Swing-JFC/CatalogSwing-JFC.htm
    – mKorbel
    Jul 29, 2011 at 20:38
  • @mKorbel is correct. Here's an example that works with your border; it might make a good sscce. You also might look for a null border setting.
    – trashgod
    Jul 29, 2011 at 21:09
  • @mKorbel All this is new to me but I took your comment to mean open a new question instead on continuing with this one. So I did.
    – splatek
    Jul 29, 2011 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.