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?

splatek
  • 111
  • 1
  • 3

1 Answers1

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);
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 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 '11 at 20:18
  • 1
    @splatek but that topic for new question, with your code ... http://www.java2s.com/Code/Java/Swing-JFC/CatalogSwing-JFC.htm – mKorbel Jul 29 '11 at 20:38
  • @mKorbel is correct. Here's an [example](http://stackoverflow.com/questions/6873665/jtable-row-selection-background-problem/6874437#6874437) that works with your border; it might make a good [sscce](http://sscce.org/). You also might look for a `null` border setting. – trashgod Jul 29 '11 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 '11 at 21:58