Displays an entry in a tree. DefaultTreeCellRenderer is not opaque and unless you subclass paint you should not change this. See How to Use Trees in The Java Tutorial for examples of customizing node display using this class.

Implementation Note: This class overrides invalidate, validate, revalidate, repaint, and firePropertyChange solely to improve performance. If not overridden, these frequently called methods would execute code paths that are unnecessary for the default tree cell renderer. If you write your own renderer, take care to weigh the benefits and drawbacks of overriding these methods.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.

borderSelectionColor

HtmlTreeCellRenderer

Returns a new instance of DefaultTreeCellRenderer. Alignment is set to left aligned. Icons and text color are determined from the UIManager.

Method Detail

getDefaultOpenIcon

public javax.swing.Icon getDefaultOpenIcon()

Returns the default icon, for the current laf, that is used to represent non-leaf nodes that are expanded.

getDefaultClosedIcon

public javax.swing.Icon getDefaultClosedIcon()

Returns the default icon, for the current laf, that is used to represent non-leaf nodes that are not expanded.

getDefaultLeafIcon

public javax.swing.Icon getDefaultLeafIcon()

Returns the default icon, for the current laf, that is used to represent leaf nodes.

setOpenIcon

public void setOpenIcon(javax.swing.Icon newIcon)

Sets the icon used to represent non-leaf nodes that are expanded.

getOpenIcon

public javax.swing.Icon getOpenIcon()

Returns the icon used to represent non-leaf nodes that are expanded.

setClosedIcon

public void setClosedIcon(javax.swing.Icon newIcon)

Sets the icon used to represent non-leaf nodes that are not expanded.

getClosedIcon

public javax.swing.Icon getClosedIcon()

Returns the icon used to represent non-leaf nodes that are not expanded.

setLeafIcon

public void setLeafIcon(javax.swing.Icon newIcon)

Sets the icon used to represent leaf nodes.

getLeafIcon

public javax.swing.Icon getLeafIcon()

Returns the icon used to represent leaf nodes.

setTextSelectionColor

public void setTextSelectionColor(java.awt.Color newColor)

Sets the color the text is drawn with when the node is selected.

getTextSelectionColor

public java.awt.Color getTextSelectionColor()

Returns the color the text is drawn with when the node is selected.

setTextNonSelectionColor

public void setTextNonSelectionColor(java.awt.Color newColor)

Sets the color the text is drawn with when the node isn't selected.

getTextNonSelectionColor

public java.awt.Color getTextNonSelectionColor()

Returns the color the text is drawn with when the node isn't selected.

setBackgroundSelectionColor

public void setBackgroundSelectionColor(java.awt.Color newColor)

Sets the color to use for the background if node is selected.

getBackgroundSelectionColor

public java.awt.Color getBackgroundSelectionColor()

Returns the color to use for the background if node is selected.

setBackgroundNonSelectionColor

public void setBackgroundNonSelectionColor(java.awt.Color newColor)

Sets the background color to be used for non selected nodes.

getBackgroundNonSelectionColor

public java.awt.Color getBackgroundNonSelectionColor()

Returns the background color to be used for non selected nodes.

setBorderSelectionColor

public void setBorderSelectionColor(java.awt.Color newColor)

Sets the color to use for the border.

getBorderSelectionColor

public java.awt.Color getBorderSelectionColor()

Returns the color the border is drawn.

setFont

public void setFont(java.awt.Font font)

Subclassed to map FontUIResources to null. If font is null, or a FontUIResource, this has the effect of letting the font of the JTree show through. On the other hand, if font is non-null, and not a FontUIResource, the font becomes font.

Overrides:

setFont in class javax.swing.JComponent

getFont

public java.awt.Font getFont()

Gets the font of this component.

Specified by:

getFont in interface java.awt.MenuContainer

Overrides:

getFont in class java.awt.Component

Returns:

this component's font; if a font has not been set for this component, the font of its parent is returned

setBackground

public void setBackground(java.awt.Color color)

Subclassed to map ColorUIResources to null. If color is null, or a ColorUIResource, this has the effect of letting the background color of the JTree show through. On the other hand, if color is non-null, and not a ColorUIResource, the background becomes color.

Overrides:

setBackground in class javax.swing.JComponent

getTreeCellRendererComponent

Configures the renderer based on the passed in components. The value is set from messaging the tree with convertValueToText, which ultimately invokes toString on value. The foreground color is set based on the selection and the icon is set based on on leaf and expanded.