posted 16 years ago
Rendering in JTables (and JTrees, JLists and JComboBoxes as well) is done through Renderers (TableCellRenderer, TreeCellRenderer, ListCellRenderer). All these interfaces have a default implementation called Default<InterfaceName>.
You must assign these renderers to the control. JTrees, JLists and JComboBoxes have simple getter and setter methods.
JTables work a little differently. First of all, you can explicitly set a renderer for a TableColumn.
However, you can also specify it for a complete set of classes. JTable has methods called getDefaultRenderer and setDefaultRenderer, where you give a TableCellRenderer and a class. When painting the table, it will call the TableModel's getColumnClass method to determine the class of the column. It will then use best matching to find the renderer. Let's say the class is Integer, it will look for Integer first. If it can't find a renderer for that class, it will look for Number next, and finally Object. This works on classes only, not interfaces, so setting the default renderer for let's say a Serializable or Cloneable will make no sense.
Explicit renderers overwrite this behaviour though.