Originally posted by Craig Wood:
I would avoid the plaf code option.
Possibilities:
1 — make a method in your app that will do this for each table
2 — make and use a special JTable class that overrides the method
Thanks for the suggestions.
I don't want to do it that way because I want to encourage a consistent JTable look and feel throught the application without needing to edit every place in the code that creates a JTable. The application has a plug-in architecture (partially), so I can't control the code written by others.
Anyway, I found a fairly simple answer to my own question, and I'm going to try this for a while.
Somewhere in the start-up of the application I call:
Where the class MyTableUI is defined like this:
I've left off the import statements, as well as the definition for ColorTableCellRenderer() and ColorTableCellEditor(). Those are based on the ones in Sun's tutorials, but are modified such that "focus", "selected" and "editable" are all taken into account in the same way that they are for the DefaultTableCellRenderer.
Note that this simply re-defines the default renderers for JTable. These defaults can still be overridden by any specific JTable. And I have tested that this looks good with the three big Look-and-Feels: Metal, Aqua, and Windows.
I hope this proves useful to others. It really bothers me that the default renderer for Boolean objects doesn't give good feedback for keyboard focus the way the DefaultTableCellRenderer does. I consider that a bug in Swing. Now that I'm used to using this renderer, it is hard to live without it in other applications.