javax.swing.tree

Class DefaultTreeCellRenderer

public class DefaultTreeCellRenderer extends JLabel implements TreeCellRenderer

A default implementation of the {@link TreeCellRenderer} interface.
Field Summary
protected ColorbackgroundNonSelectionColor
The background color for non-selected cells.
protected ColorbackgroundSelectionColor
The background color for selected cells.
protected ColorborderSelectionColor
The border color for selected tree cells.
protected IconclosedIcon
The icon used to represent non-leaf nodes that are closed.
protected booleanhasFocus
A flag indicating the current focus status.
protected IconleafIcon
The icon used to represent leaf nodes.
protected IconopenIcon
The icon used to represent non-leaf nodes that are open.
protected booleanselected
A flag indicating the current selection status.
protected ColortextNonSelectionColor
The color used for text in non-selected cells.
protected ColortextSelectionColor
The color used for text in selected cells.
Constructor Summary
DefaultTreeCellRenderer()
Creates a new tree cell renderer with defaults appropriate for the current {@link LookAndFeel}.
Method Summary
protected voidfirePropertyChange(String name, Object oldValue, Object newValue)
For performance reasons, this method is overridden to do nothing.
voidfirePropertyChange(String name, byte oldValue, byte newValue)
For performance reasons, this method is overridden to do nothing.
voidfirePropertyChange(String name, char oldValue, char newValue)
For performance reasons, this method is overridden to do nothing.
voidfirePropertyChange(String name, short oldValue, short newValue)
For performance reasons, this method is overridden to do nothing.
voidfirePropertyChange(String name, int oldValue, int newValue)
For performance reasons, this method is overridden to do nothing.
voidfirePropertyChange(String name, long oldValue, long newValue)
For performance reasons, this method is overridden to do nothing.
voidfirePropertyChange(String name, float oldValue, float newValue)
For performance reasons, this method is overridden to do nothing.
voidfirePropertyChange(String name, double oldValue, double newValue)
For performance reasons, this method is overridden to do nothing.
voidfirePropertyChange(String name, boolean oldValue, boolean newValue)
For performance reasons, this method is overridden to do nothing.
ColorgetBackgroundNonSelectionColor()
Returns the background color for tree cells that are not selected.
ColorgetBackgroundSelectionColor()
Returns the background color for tree cells that are selected.
ColorgetBorderSelectionColor()
Returns the border color for tree cells that are selected.
IcongetClosedIcon()
Returns the icon displayed for non-leaf nodes that are closed.
IcongetDefaultClosedIcon()
Returns the default icon for non-leaf tree cells that are closed (not expanded).
IcongetDefaultLeafIcon()
Returns the default icon for leaf tree cells.
IcongetDefaultOpenIcon()
Returns the default icon for non-leaf tree cells that are open (expanded).
FontgetFont()
Returns the current font.
IcongetLeafIcon()
Returns the icon displayed for leaf nodes.
IcongetOpenIcon()
Returns the icon displayed for non-leaf nodes that are open (expanded).
DimensiongetPreferredSize()
Returns the preferred size of the cell.
ColorgetTextNonSelectionColor()
Returns the text color for tree cells that are not selected.
ColorgetTextSelectionColor()
Returns the text color for tree cells that are selected.
ComponentgetTreeCellRendererComponent(JTree tree, Object val, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
Returns a component (in fact this) that can be used to render a tree cell with the specified state.
voidpaint(Graphics g)
Paints the value.
voidrepaint(long tm, int x, int y, int width, int height)
For performance reasons, this method is overridden to do nothing.
voidrepaint(Rectangle area)
For performance reasons, this method is overridden to do nothing.
voidrevalidate()
For performance reasons, this method is overridden to do nothing.
voidsetBackground(Color c)
Sets the background color.
voidsetBackgroundNonSelectionColor(Color c)
Sets the background color for tree cells that are not selected.
voidsetBackgroundSelectionColor(Color c)
Sets the background color for tree cells that are selected.
voidsetBorderSelectionColor(Color c)
Sets the border color for tree cells that are selected.
voidsetClosedIcon(Icon icon)
Sets the icon to be displayed for non-leaf nodes that are closed.
voidsetFont(Font f)
Sets the font.
voidsetLeafIcon(Icon icon)
Sets the icon to be displayed for leaf nodes.
voidsetOpenIcon(Icon icon)
Sets the icon to be displayed for non-leaf nodes that are open (expanded).
voidsetTextNonSelectionColor(Color c)
Sets the text color for tree cells that are not selected.
voidsetTextSelectionColor(Color c)
Sets the text color for tree cells that are selected.
voidvalidate()
For performance reasons, this method is overridden to do nothing.

Field Detail

backgroundNonSelectionColor

protected Color backgroundNonSelectionColor
The background color for non-selected cells.

See Also: setBackgroundNonSelectionColor

backgroundSelectionColor

protected Color backgroundSelectionColor
The background color for selected cells.

See Also: setBackgroundSelectionColor

borderSelectionColor

protected Color borderSelectionColor
The border color for selected tree cells.

See Also: setBorderSelectionColor

closedIcon

protected transient Icon closedIcon
The icon used to represent non-leaf nodes that are closed.

See Also: setClosedIcon

hasFocus

protected boolean hasFocus
A flag indicating the current focus status.

leafIcon

protected transient Icon leafIcon
The icon used to represent leaf nodes.

See Also: setLeafIcon

openIcon

protected transient Icon openIcon
The icon used to represent non-leaf nodes that are open.

See Also: setOpenIcon

selected

protected boolean selected
A flag indicating the current selection status.

textNonSelectionColor

protected Color textNonSelectionColor
The color used for text in non-selected cells.

See Also: setTextNonSelectionColor

textSelectionColor

protected Color textSelectionColor
The color used for text in selected cells.

See Also: setTextSelectionColor

Constructor Detail

DefaultTreeCellRenderer

public DefaultTreeCellRenderer()
Creates a new tree cell renderer with defaults appropriate for the current {@link LookAndFeel}.

Method Detail

firePropertyChange

protected void firePropertyChange(String name, Object oldValue, Object newValue)
For performance reasons, this method is overridden to do nothing.

Parameters: name the property name. oldValue the old value. newValue the new value.

firePropertyChange

public void firePropertyChange(String name, byte oldValue, byte newValue)
For performance reasons, this method is overridden to do nothing.

Parameters: name the property name. oldValue the old value. newValue the new value.

firePropertyChange

public void firePropertyChange(String name, char oldValue, char newValue)
For performance reasons, this method is overridden to do nothing.

Parameters: name the property name. oldValue the old value. newValue the new value.

firePropertyChange

public void firePropertyChange(String name, short oldValue, short newValue)
For performance reasons, this method is overridden to do nothing.

Parameters: name the property name. oldValue the old value. newValue the new value.

firePropertyChange

public void firePropertyChange(String name, int oldValue, int newValue)
For performance reasons, this method is overridden to do nothing.

Parameters: name the property name. oldValue the old value. newValue the new value.

firePropertyChange

public void firePropertyChange(String name, long oldValue, long newValue)
For performance reasons, this method is overridden to do nothing.

Parameters: name the property name. oldValue the old value. newValue the new value.

firePropertyChange

public void firePropertyChange(String name, float oldValue, float newValue)
For performance reasons, this method is overridden to do nothing.

Parameters: name the property name. oldValue the old value. newValue the new value.

firePropertyChange

public void firePropertyChange(String name, double oldValue, double newValue)
For performance reasons, this method is overridden to do nothing.

Parameters: name the property name. oldValue the old value. newValue the new value.

firePropertyChange

public void firePropertyChange(String name, boolean oldValue, boolean newValue)
For performance reasons, this method is overridden to do nothing.

Parameters: name the property name. oldValue the old value. newValue the new value.

getBackgroundNonSelectionColor

public Color getBackgroundNonSelectionColor()
Returns the background color for tree cells that are not selected. The default value is obtained from the {@link LookAndFeel} defaults table using the key Tree.textBackground.

Returns: The background color for tree cells that are not selected.

See Also: setBackgroundNonSelectionColor

getBackgroundSelectionColor

public Color getBackgroundSelectionColor()
Returns the background color for tree cells that are selected. The default value is obtained from the {@link LookAndFeel} defaults table using the key Tree.selectionBackground.

Returns: The background color for tree cells that are selected.

See Also: setBackgroundSelectionColor

getBorderSelectionColor

public Color getBorderSelectionColor()
Returns the border color for tree cells that are selected. The default value is obtained from the {@link LookAndFeel} defaults table using the key Tree.selectionBorderColor.

Returns: The border color for tree cells that are selected.

See Also: setBorderSelectionColor

getClosedIcon

public Icon getClosedIcon()
Returns the icon displayed for non-leaf nodes that are closed. The default value is initialised from the {@link LookAndFeel}.

Returns: The closed icon (possibly null).

See Also: setClosedIcon

getDefaultClosedIcon

public Icon getDefaultClosedIcon()
Returns the default icon for non-leaf tree cells that are closed (not expanded). The icon is fetched from the defaults table for the current {@link LookAndFeel} using the key Tree.closedIcon.

Returns: The default icon.

getDefaultLeafIcon

public Icon getDefaultLeafIcon()
Returns the default icon for leaf tree cells. The icon is fetched from the defaults table for the current {@link LookAndFeel} using the key Tree.leafIcon.

Returns: The default icon.

getDefaultOpenIcon

public Icon getDefaultOpenIcon()
Returns the default icon for non-leaf tree cells that are open (expanded). The icon is fetched from the defaults table for the current {@link LookAndFeel} using the key Tree.openIcon.

Returns: The default icon.

getFont

public Font getFont()
Returns the current font.

Returns: The current font.

See Also: setFont

getLeafIcon

public Icon getLeafIcon()
Returns the icon displayed for leaf nodes. The default value is initialised from the {@link LookAndFeel}.

Returns: The leaf icon (possibly null).

See Also: setLeafIcon

getOpenIcon

public Icon getOpenIcon()
Returns the icon displayed for non-leaf nodes that are open (expanded). The default value is initialised from the {@link LookAndFeel}.

Returns: The open icon (possibly null).

See Also: setOpenIcon

getPreferredSize

public Dimension getPreferredSize()
Returns the preferred size of the cell.

Returns: The preferred size of the cell.

getTextNonSelectionColor

public Color getTextNonSelectionColor()
Returns the text color for tree cells that are not selected. The default value is obtained from the {@link LookAndFeel} defaults table using the key Tree.selectionForeground.

Returns: The background color for tree cells that are not selected.

See Also: DefaultTreeCellRenderer

getTextSelectionColor

public Color getTextSelectionColor()
Returns the text color for tree cells that are selected. The default value is obtained from the {@link LookAndFeel} defaults table using the key Tree.selectionForeground.

Returns: The text color for tree cells that are selected.

See Also: setTextSelectionColor

getTreeCellRendererComponent

public Component getTreeCellRendererComponent(JTree tree, Object val, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
Returns a component (in fact this) that can be used to render a tree cell with the specified state.

Parameters: tree the tree that the cell belongs to. val the cell value. selected indicates whether or not the cell is selected. expanded indicates whether or not the cell is expanded. leaf indicates whether or not the cell is a leaf in the tree. row the row index. hasFocus indicates whether or not the cell has the focus.

Returns: this.

paint

public void paint(Graphics g)
Paints the value. The background is filled based on selected.

Parameters: g the graphics device.

repaint

public void repaint(long tm, int x, int y, int width, int height)
For performance reasons, this method is overridden to do nothing.

Parameters: tm ignored x coordinate of the region to mark as dirty y coordinate of the region to mark as dirty width dimension of the region to mark as dirty height dimension of the region to mark as dirty

repaint

public void repaint(Rectangle area)
For performance reasons, this method is overridden to do nothing.

Parameters: area the area to repaint.

revalidate

public void revalidate()
For performance reasons, this method is overridden to do nothing.

setBackground

public void setBackground(Color c)
Sets the background color.

Parameters: c the color.

setBackgroundNonSelectionColor

public void setBackgroundNonSelectionColor(Color c)
Sets the background color for tree cells that are not selected.

Parameters: c the color (null permitted).

See Also: getBackgroundNonSelectionColor

setBackgroundSelectionColor

public void setBackgroundSelectionColor(Color c)
Sets the background color for tree cells that are selected.

Parameters: c the color (null permitted).

See Also: getBackgroundSelectionColor

setBorderSelectionColor

public void setBorderSelectionColor(Color c)
Sets the border color for tree cells that are selected.

Parameters: c the color (null permitted).

See Also: getBorderSelectionColor

setClosedIcon

public void setClosedIcon(Icon icon)
Sets the icon to be displayed for non-leaf nodes that are closed. Set this to null if no icon is required.

Parameters: icon the icon (null permitted).

See Also: getClosedIcon

setFont

public void setFont(Font f)
Sets the font.

Parameters: f the font.

See Also: getFont

setLeafIcon

public void setLeafIcon(Icon icon)
Sets the icon to be displayed for leaf nodes. Set this to null if no icon is required.

Parameters: icon the icon (null permitted).

See Also: getLeafIcon

setOpenIcon

public void setOpenIcon(Icon icon)
Sets the icon to be displayed for non-leaf nodes that are open (expanded). Set this to null if no icon is required.

Parameters: icon the icon (null permitted).

See Also: getOpenIcon

setTextNonSelectionColor

public void setTextNonSelectionColor(Color c)
Sets the text color for tree cells that are not selected.

Parameters: c the color (null permitted).

See Also: getTextNonSelectionColor

setTextSelectionColor

public void setTextSelectionColor(Color c)
Sets the text color for tree cells that are selected.

Parameters: c the color (null permitted).

See Also: getTextSelectionColor

validate

public void validate()
For performance reasons, this method is overridden to do nothing.