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.
The set of icons and colors used by DefaultTreeCellRenderer
can be configured using the various setter methods. The value for
each property is initialized from the defaults table. When the
look and feel changes (updateUI is invoked), any properties
that have a value of type UIResource are refreshed from the
defaults table. The following table lists the mapping between
DefaultTreeCellRenderer property and defaults table key:
| Property | Key |
|---|---|
| "leafIcon" | "Tree.leafIcon" |
| "closedIcon" | "Tree.closedIcon" |
| "openIcon" | "Tree.openIcon" |
| "textSelectionColor" | "Tree.selectionForeground" |
| "textNonSelectionColor" | "Tree.textForeground" |
| "backgroundSelectionColor" | "Tree.selectionBackground" |
| "backgroundNonSelectionColor" | "Tree.textBackground" |
| "borderSelectionColor" | "Tree.selectionBorderColor" |
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 JavaBeans
has been added to the java.beans package.
Please see java..
| Modifier and Type | Field and Description |
|---|---|
| protected Color | backgroundNonSelectionColor
Color to use for the background when the node isn't selected. |
| protected Color | backgroundSelectionColor
Color to use for the background when a node is selected. |
| protected Color | borderSelectionColor
Color to use for the focus indicator when the node has focus. |
| protected transient Icon | closedIcon
Icon used to show non-leaf nodes that aren't expanded. |
| private boolean | drawDashedFocusIndicator
If true, a dashed line is drawn as the focus indicator. |
| private boolean | drawsFocusBorderAroundIcon
True if draws focus border around icon as well. |
| private boolean | |
| private Color | focusBGColor
Color to draw the focus indicator in, determined from the background. |
| protected boolean | hasFocus
True if has focus. |
| private boolean | inited
Set to true after the constructor has run. |
| private boolean | |
| protected transient Icon | leafIcon
Icon used to show leaf nodes. |
| protected transient Icon | openIcon
Icon used to show non-leaf nodes that are expanded. |
| protected boolean | selected
Is the value currently selected. |
| protected Color | textNonSelectionColor
Color to use for the foreground for non-selected nodes. |
| protected Color | textSelectionColor
Color to use for the foreground for selected nodes. |
| private JTree | tree
Last tree the renderer was painted in. |
| private Color | treeBGColor
Background color of the tree. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | firePropertyChange(String propertyName, Object oldValue, Object newValue)
Overrides java. Overridden for performance reasons. |
| public void | firePropertyChange(String propertyName, byte oldValue, byte newValue)
Overrides java. Overridden for performance reasons. |
| public void | firePropertyChange(String propertyName, char oldValue, char newValue)
Overrides javax. Overridden for performance reasons. |
| public void | firePropertyChange(String propertyName, short oldValue, short newValue)
Overrides java. Overridden for performance reasons. |
| public void | firePropertyChange(String propertyName, int oldValue, int newValue)
Overrides javax. Overridden for performance reasons. |
| public void | firePropertyChange(String propertyName, long oldValue, long newValue)
Overrides java. Overridden for performance reasons. |
| public void | firePropertyChange(String propertyName, float oldValue, float newValue)
Overrides java. Overridden for performance reasons. |
| public void | firePropertyChange(String propertyName, double oldValue, double newValue)
Overrides java. Overridden for performance reasons. |
| public void | firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
Overrides javax. Overridden for performance reasons. |
| public Color | Returns: the background color to be used for non selected nodes.Returns the background color to be used for non selected nodes. |
| public Color | Returns: the color to use for the background if node is selectedReturns the color to use for the background if node is selected. |
| public Color | Returns: the color the border is drawnReturns the color the border is drawn. |
| public Icon | Returns: the icon used to represent non-leaf nodes that are not expandedReturns the icon used to represent non-leaf nodes that are not expanded. |
| public Icon | Returns: the default icon, for the current laf, that is used to represent non-leaf nodes that are not expanded.Returns the default icon, for the current laf, that is used to represent non-leaf nodes that are not expanded. |
| public Icon | Returns: the default icon, for the current laf, that is used to represent leaf nodes.Returns the default icon, for the current laf, that is used to represent leaf nodes. |
| public Icon | Returns: the default icon, for the current laf, that is used to represent non-leaf nodes that are expanded.Returns the default icon, for the current laf, that is used to represent non-leaf nodes that are expanded. |
| public Font | Returns: this component's font; if a font has not been set for this component, the font of its parent is returnedOverrides java. Implements java. Gets the font of this component. |
| private int | |
| public Icon | Returns: the icon used to represent leaf nodesReturns the icon used to represent leaf nodes. |
| public Icon | Returns: the icon used to represent non-leaf nodes that are expandedReturns the icon used to represent non-leaf nodes that are expanded. |
| public Dimension | getPreferredSize()
Overrides javax. Overrides |
| public Color | Returns: the color the text is drawn with when the node isn't selected.Returns the color the text is drawn with when the node isn't selected. |
| public Color | Returns: the color the text is drawn with when the node is selectedReturns the color the text is drawn with when the node is selected. |
| public Component | getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
Implements javax. Configures the renderer based on the passed in components. |
| public void | |
| public void | |
| private void | |
| public void | repaint(long tm, int x, int y, int width, int height)
Overrides javax. Overridden for performance reasons. |
| public void | |
| public void | |
| public void | |
| public void | setBackground(Color color)
Overrides javax. Subclassed to map |
| public void | setBackgroundNonSelectionColor(Color
color to be used for the background for non selected nodes newColor)Sets the background color to be used for non selected nodes. |
| public void | setBackgroundSelectionColor(Color
to be used for the background if the node is selected newColor)Sets the color to use for the background if node is selected. |
| public void | setBorderSelectionColor(Color
color to be used for the border newColor)Sets the color to use for the border. |
| public void | setClosedIcon(Icon
the icon to be used for not expanded non-leaf nodes newIcon)Sets the icon used to represent non-leaf nodes that are not expanded. |
| public void | setFont(Font font)
Overrides javax. Subclassed to map |
| public void | |
| public void | setOpenIcon(Icon
the icon to be used for expanded non-leaf nodes newIcon)Sets the icon used to represent non-leaf nodes that are expanded. |
| public void | setTextNonSelectionColor(Color
color to be used for text when the node isn't selected newColor)Sets the color the text is drawn with when the node isn't selected. |
| public void | setTextSelectionColor(Color
color to be used for text when the node is selected newColor)Sets the color the text is drawn with when the node is selected. |
| public void | updateUI()
Overrides javax. Resets the UI property to a value from the current look and feel. |
| public void |
| backgroundNonSelectionColor | back to summary |
|---|---|
| protected Color backgroundNonSelectionColor Color to use for the background when the node isn't selected. | |
| backgroundSelectionColor | back to summary |
|---|---|
| protected Color backgroundSelectionColor Color to use for the background when a node is selected. | |
| borderSelectionColor | back to summary |
|---|---|
| protected Color borderSelectionColor Color to use for the focus indicator when the node has focus. | |
| closedIcon | back to summary |
|---|---|
| protected transient Icon closedIcon Icon used to show non-leaf nodes that aren't expanded. | |
| drawDashedFocusIndicator | back to summary |
|---|---|
| private boolean drawDashedFocusIndicator If true, a dashed line is drawn as the focus indicator. | |
| drawsFocusBorderAroundIcon | back to summary |
|---|---|
| private boolean drawsFocusBorderAroundIcon True if draws focus border around icon as well. | |
| fillBackground | back to summary |
|---|---|
| private boolean fillBackground | |
| focusBGColor | back to summary |
|---|---|
| private Color focusBGColor Color to draw the focus indicator in, determined from the background. color. | |
| hasFocus | back to summary |
|---|---|
| protected boolean hasFocus True if has focus. | |
| inited | back to summary |
|---|---|
| private boolean inited Set to true after the constructor has run. | |
| isDropCell | back to summary |
|---|---|
| private boolean isDropCell | |
| leafIcon | back to summary |
|---|---|
| protected transient Icon leafIcon Icon used to show leaf nodes. | |
| openIcon | back to summary |
|---|---|
| protected transient Icon openIcon Icon used to show non-leaf nodes that are expanded. | |
| selected | back to summary |
|---|---|
| protected boolean selected Is the value currently selected. | |
| textNonSelectionColor | back to summary |
|---|---|
| protected Color textNonSelectionColor Color to use for the foreground for non-selected nodes. | |
| textSelectionColor | back to summary |
|---|---|
| protected Color textSelectionColor Color to use for the foreground for selected nodes. | |
| tree | back to summary |
|---|---|
| private JTree tree Last tree the renderer was painted in. | |
| treeBGColor | back to summary |
|---|---|
| private Color treeBGColor Background color of the tree. | |
| DefaultTreeCellRenderer | back to summary |
|---|---|
| public DefaultTreeCellRenderer() Creates a | |
| firePropertyChange | back to summary |
|---|---|
| protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) Overrides java. Overridden for performance reasons. See the Implementation Note for more information. | |
| firePropertyChange | back to summary |
|---|---|
| public void firePropertyChange(String propertyName, byte oldValue, byte newValue) Overrides java. Overridden for performance reasons. See the Implementation Note for more information. | |
| firePropertyChange | back to summary |
|---|---|
| public void firePropertyChange(String propertyName, char oldValue, char newValue) Overrides javax. Overridden for performance reasons. See the Implementation Note for more information. | |
| firePropertyChange | back to summary |
|---|---|
| public void firePropertyChange(String propertyName, short oldValue, short newValue) Overrides java. Overridden for performance reasons. See the Implementation Note for more information. | |
| firePropertyChange | back to summary |
|---|---|
| public void firePropertyChange(String propertyName, int oldValue, int newValue) Overrides javax. Overridden for performance reasons. See the Implementation Note for more information. | |
| firePropertyChange | back to summary |
|---|---|
| public void firePropertyChange(String propertyName, long oldValue, long newValue) Overrides java. Overridden for performance reasons. See the Implementation Note for more information. | |
| firePropertyChange | back to summary |
|---|---|
| public void firePropertyChange(String propertyName, float oldValue, float newValue) Overrides java. Overridden for performance reasons. See the Implementation Note for more information. | |
| firePropertyChange | back to summary |
|---|---|
| public void firePropertyChange(String propertyName, double oldValue, double newValue) Overrides java. Overridden for performance reasons. See the Implementation Note for more information. | |
| firePropertyChange | back to summary |
|---|---|
| public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) Overrides javax. Overridden for performance reasons. See the Implementation Note for more information. | |
| getBackgroundNonSelectionColor | back to summary |
|---|---|
| public Color getBackgroundNonSelectionColor() Returns the background color to be used for non selected nodes.
| |
| getBackgroundSelectionColor | back to summary |
|---|---|
| public Color getBackgroundSelectionColor() Returns the color to use for the background if node is selected.
| |
| getBorderSelectionColor | back to summary |
|---|---|
| public Color getBorderSelectionColor() Returns the color the border is drawn.
| |
| getClosedIcon | back to summary |
|---|---|
| public Icon getClosedIcon() Returns the icon used to represent non-leaf nodes that are not expanded.
| |
| getDefaultClosedIcon | back to summary |
|---|---|
| public Icon getDefaultClosedIcon() Returns the default icon, for the current laf, that is used to represent non-leaf nodes that are not expanded.
| |
| getDefaultLeafIcon | back to summary |
|---|---|
| public Icon getDefaultLeafIcon() Returns the default icon, for the current laf, that is used to represent leaf nodes.
| |
| getDefaultOpenIcon | back to summary |
|---|---|
| public Icon getDefaultOpenIcon() Returns the default icon, for the current laf, that is used to represent non-leaf nodes that are expanded.
| |
| getFont | back to summary |
|---|---|
| public Font getFont() Overrides java. Implements java. Gets the font of this component.
| |
| getLabelStart | back to summary |
|---|---|
| private int getLabelStart() | |
| getLeafIcon | back to summary |
|---|---|
| public Icon getLeafIcon() Returns the icon used to represent leaf nodes.
| |
| getOpenIcon | back to summary |
|---|---|
| public Icon getOpenIcon() Returns the icon used to represent non-leaf nodes that are expanded.
| |
| getPreferredSize | back to summary |
|---|---|
| public Dimension getPreferredSize() Overrides javax. Overrides | |
| getTextNonSelectionColor | back to summary |
|---|---|
| public Color getTextNonSelectionColor() Returns the color the text is drawn with when the node isn't selected.
| |
| getTextSelectionColor | back to summary |
|---|---|
| public Color getTextSelectionColor() Returns the color the text is drawn with when the node is selected.
| |
| getTreeCellRendererComponent | back to summary |
|---|---|
| public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) Implements javax. Configures the renderer based on the passed in components.
The value is set from messaging the tree with
| |
| invalidate | back to summary |
|---|---|
| public void invalidate() Overrides java. Overridden for performance reasons. See the Implementation Note for more information.
| |
| paint | back to summary |
|---|---|
| public void paint(Graphics g) Overrides javax. Paints the value. The background is filled based on selected. | |
| paintFocus | back to summary |
|---|---|
| private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) | |
| repaint | back to summary |
|---|---|
| public void repaint(long tm, int x, int y, int width, int height) Overrides javax. Overridden for performance reasons. See the Implementation Note for more information. | |
| repaint | back to summary |
|---|---|
| public void repaint(Rectangle r) Overrides javax. Overridden for performance reasons. See the Implementation Note for more information. | |
| repaint | back to summary |
|---|---|
| public void repaint() Overrides java. Overridden for performance reasons. See the Implementation Note for more information.
| |
| revalidate | back to summary |
|---|---|
| public void revalidate() Overrides javax. Overridden for performance reasons. See the Implementation Note for more information. | |
| setBackground | back to summary |
|---|---|
| public void setBackground(Color color) Overrides javax. Subclassed to map | |
| setBackgroundNonSelectionColor | back to summary |
|---|---|
| public void setBackgroundNonSelectionColor(Color newColor) Sets the background color to be used for non selected nodes.
| |
| setBackgroundSelectionColor | back to summary |
|---|---|
| public void setBackgroundSelectionColor(Color newColor) Sets the color to use for the background if node is selected.
| |
| setBorderSelectionColor | back to summary |
|---|---|
| public void setBorderSelectionColor(Color newColor) Sets the color to use for the border.
| |
| setClosedIcon | back to summary |
|---|---|
| public void setClosedIcon(Icon newIcon) Sets the icon used to represent non-leaf nodes that are not expanded.
| |
| setFont | back to summary |
|---|---|
| public void setFont(Font font) Overrides javax. Subclassed to map | |
| setLeafIcon | back to summary |
|---|---|
| public void setLeafIcon(Icon newIcon) Sets the icon used to represent leaf nodes.
| |
| setOpenIcon | back to summary |
|---|---|
| public void setOpenIcon(Icon newIcon) Sets the icon used to represent non-leaf nodes that are expanded.
| |
| setTextNonSelectionColor | back to summary |
|---|---|
| public void setTextNonSelectionColor(Color newColor) Sets the color the text is drawn with when the node isn't selected.
| |
| setTextSelectionColor | back to summary |
|---|---|
| public void setTextSelectionColor(Color newColor) Sets the color the text is drawn with when the node is selected.
| |
| updateUI | back to summary |
|---|---|
| public void updateUI() Overrides javax. Doc from javax. Resets the UI property to a value from the current look and feel.
| |
| validate | back to summary |
|---|---|
| public void validate() Overrides java. Overridden for performance reasons. See the Implementation Note for more information. | |