Once you have a new renderer, you can put it to use by connecting it to a
table with the setDefaultRenderer
method. Note, however, that
renderers are associated with column classes, which are determined by the
getColumnClass
method in the table model. The definition of
getColumnClass
defined by the DefaultTableModel
class
inconveniently reports every column as having an Object
column
class.
Accordingly, you need to modify the behavior of the getColumnClass
method by
having it report the class of the element in the
zeroth row; you obtain that class using the getClass
method:
import java.util.*; import javax.swing.table.*; public class RatingTableModel extends DefaultTableModel { public RatingTableModel (Vector rows, Vector columns) { super(rows, columns); } public boolean isCellEditable(int row, int column) { return false; } // Define shadowing method public Class getColumnClass(int column) { return getValueAt(0, column).getClass(); } }