Java Reference
In-Depth Information
When it's time to draw a tree node, that tree asks its registered TreeCellRenderer how to
display that specific node. The node itself is passed in as the value argument so that the renderer
has access to its current state to determine how to render this state. To change the installed
renderer, use public void setCellRenderer(TreeCellRenderer renderer) .
DefaultTreeCellRenderer Class
The DefaultTreeCellRenderer class serves as the default tree cell renderer. This class is a JLabel
subclass, so it can support capabilities such as displaying tooltip text or pop-up menus specific
to a node. It has only a no-argument constructor.
When used by a JTree , the DefaultTreeCellRenderer uses the various default icons (as
shown earlier in Figure 17-5) to display the current state of the node and a text representation
of the data for the node. The text representation is acquired by calling the toString() method
for each node of the tree.
DefaultTreeCellRenderer Properties
Table 17-3 shows the 14 properties added (or altered) with DefaultTreeCellRenderer . Because
the default renderer happens to be a JLabel , you also acquire many additional properties from it.
Table 17-3. DefaultTreeCellRenderer Properties
Property Name
Data Type
Access
background
Color
Write-only
backgroundNonSelectionColor
Color
Read-write
backgroundSelectionColor
Color
Read-write
borderSelectionColor
Color
Read-write
closedIcon
Icon
Read-write
defaultClosedIcon
Icon
Read-only
defaultLeafIcon
Icon
Read-only
defaultOpenIcon
Icon
Read-only
font
Font
Read-write
leafIcon
Icon
Read-write
openIcon
Icon
Read-write
preferredSize
Dimension
Read-only
textNonSelectionColor
Color
Read-write
textSelectionColor
Color
Read-write
Search WWH ::




Custom Search