Now, you learn how to alter the
appearance of cells. The JTable
machinery obtains the
cell renderer by calling getTableCellRenderer
. Then, machinery defined
in the JTable
class displays each cell by displaying a component
produced by a cell renderer using the data associated with the cell.
Display ^ | Modified instance | *-----------------* getTableCellRenderer *-- | -------------------* | | ----------------------> | | Renderer instance | | JTable instance | | | | | | | *--------------------* | | | | | Component instance | | | | | *--------------------* | | | *-- ^ -------------------* | | | | | | Data instance | | getModel *------------------------* | | ----------------------> | Table model instance | *-----------------* *------------------------*
Fundamentally, the cell renderer uses cell data to modify a component held
by the renderer; then, the modified component is returned by the cell
renderer for display. Because the Component
class defines a
paint
method, the JTable
machinery simply calls the
paint
method using the returned component as the target.