Default<Comp>CellRenderer


Implementations

Comparing implementations (jdk1.5). Mustang?


methods/properties Table List Tree
selectionForeground methods on component
installed by UI-Delegates
textSelection: renderer-property
installed in consructor from UIManager values
selectionBackground backgroundSelection: renderer-property
installed in consructor from UIManager values
foreground (non-selection)
same as component if no implicit
renderer methods implicitly sets renderer specific colors which take precedence over table's
same as component textNotSelection: renderer-property
installed in consructor from UIManager values:
background (non-selection) backgroundNotSelection: renderer-property
installed in consructor from UIManager values
renderer color configuration calls super.setFore/Background in getRendererComp
Note: needs super.setXX to not trigger implicit color setting!
calls setFore/Background in getRendererComp setForeground in getRendererComp
manual background painting in paint
Note: manual background paint needed for of icon handling
Note: manual background paint requires state storage
focus specials background depends on editable -- border/Non/SelectionColor
updateUI resets implicit non-selection colors -- --
opaque true, magic in isOpaque --
font set to component's in getRendererComp getFont overridden to return tree's if no renderer specific set
setFont overridden to null UIResource fonts
enabled -- set to component's in getRendererComp
border set depending on cell context manual border painting in paint
componentOrientation -- (core bug #6333197 - status?) set to component's in getRendererComp
state between calls -- -- tree
selected
focused


API 

Parameters in getXXCellRendererComponent vs. members in ComponentAdapter


Parameter Table List Tree ComponentAdapter
component JTable JList JTree JComponent getComponent()
value Object Object Object Object getValue()
selected boolean boolean boolean boolean isSelected()
focused boolean boolean boolean boolean hasFocus()
expanded -- -- boolean boolean isExpanded()
leaf -- -- boolean boolean isLeaf()
editable -- -- -- --
row int int int int row
column int -- -- int column



Core Documentation

JavaDoc

JavaDoc Table List Tree
interface class doc used in paint as rubber stamp
has example
defines requirements to display a tree node
link to swing tutorial
interface method doc getXXComponent returns the component used for drawing
used to configure the renderer 
used in paint as rubber stamp
used outside of paint for calculating prefSize
returns component that the renderer uses to draw the node
default impl class doc standard class for rendering (= displaying) a table cell same (plus notes about performance overrides and serialization) same (plus notes about performance overrides and serialization)
default impl method doc returns default renderer same configures renderer based on passed-in context


Commons:

Tutorial 

Primary focus is on data-type: from how-to use tables "a cell renderer .. is used to draw all of the cells that contain the same type of data... think of it as a configurable ink stamp ... to stamp  appropriately formatted data onto each cell".

Primary customization advise: subclass the default renderer (wich is a subclass of JLabel) and/or subclass a Component to implement custom rendering requirements. (Side-note: it's on the borderline of violating the "Do not subclass Component for application need" rule).The example (ColorRenderer) again is type focused.