Re: About JTable's HeaderRenderer Class
Thursday, April 3, 2003 06:29 AM
I think the current (Java 1.4.1) cell renderer scheme works as
Each TableColumn can have its own TableCellRenderer for painting its values. You can set this
value by calling the setCellRenderer () method of the
table column or by specifying it when you create the TableColumn. By default this value is null.
A JTable maintains a default cell renderer for each object type known to it (it gets the object type from its getColumnClass () method). JTable has a default renderer for String, numbers (Integer, Float, etc), Date, Boolean, Icon and finally Object (every thing else). You can also specify a default renderer for a given class by calling JTable.setDefaultRenderer ().
When it needs to paint a given cell, JTable checks to
see if the associated TableColumn defines a cell renderer (
its getCellRenderer () returns a non-null value). If it does
not, JTable will look at the value of the cell and based on
its type picks one of the default renderers to paint the cell.
The short answer is tc.getCellRenderer () returns null
because you have not set the renderer for the column prior to this
The best way to get the renderer for a given JTable cell is by
calling JTable.getCellRenderer (row, column).