javax.swing.tree
Class DefaultTreeCellRenderer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by javax.swing.tree.DefaultTreeCellRenderer
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants, TreeCellRenderer

public class DefaultTreeCellRenderer
extends JLabel
implements TreeCellRenderer

A default implementation of the TreeCellRenderer interface.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
JLabel.AccessibleJLabel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  Color backgroundNonSelectionColor
          The background color for non-selected cells.
protected  Color backgroundSelectionColor
          The background color for selected cells.
protected  Color borderSelectionColor
          The border color for selected tree cells.
protected  Icon closedIcon
          The icon used to represent non-leaf nodes that are closed.
protected  boolean hasFocus
          A flag indicating the current focus status.
protected  Icon leafIcon
          The icon used to represent leaf nodes.
protected  Icon openIcon
          The icon used to represent non-leaf nodes that are open.
protected  boolean selected
          A flag indicating the current selection status.
protected  Color textNonSelectionColor
          The color used for text in non-selected cells.
protected  Color textSelectionColor
          The color used for text in selected cells.
 
Fields inherited from class javax.swing.JLabel
labelFor
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DefaultTreeCellRenderer()
          Creates a new tree cell renderer with defaults appropriate for the current LookAndFeel.
 
Method Summary
 void firePropertyChange(String name, boolean oldValue, boolean newValue)
          For performance reasons, this method is overridden to do nothing.
 void firePropertyChange(String name, byte oldValue, byte newValue)
          For performance reasons, this method is overridden to do nothing.
 void firePropertyChange(String name, char oldValue, char newValue)
          For performance reasons, this method is overridden to do nothing.
 void firePropertyChange(String name, double oldValue, double newValue)
          For performance reasons, this method is overridden to do nothing.
 void firePropertyChange(String name, float oldValue, float newValue)
          For performance reasons, this method is overridden to do nothing.
 void firePropertyChange(String name, int oldValue, int newValue)
          For performance reasons, this method is overridden to do nothing.
 void firePropertyChange(String name, long oldValue, long newValue)
          For performance reasons, this method is overridden to do nothing.
protected  void firePropertyChange(String name, Object oldValue, Object newValue)
          For performance reasons, this method is overridden to do nothing.
 void firePropertyChange(String name, short oldValue, short newValue)
          For performance reasons, this method is overridden to do nothing.
 Color getBackgroundNonSelectionColor()
          Returns the background color for tree cells that are not selected.
 Color getBackgroundSelectionColor()
          Returns the background color for tree cells that are selected.
 Color getBorderSelectionColor()
          Returns the border color for tree cells that are selected.
 Icon getClosedIcon()
          Returns the icon displayed for non-leaf nodes that are closed.
 Icon getDefaultClosedIcon()
          Returns the default icon for non-leaf tree cells that are closed (not expanded).
 Icon getDefaultLeafIcon()
          Returns the default icon for leaf tree cells.
 Icon getDefaultOpenIcon()
          Returns the default icon for non-leaf tree cells that are open (expanded).
 Font getFont()
          Returns the current font.
 Icon getLeafIcon()
          Returns the icon displayed for leaf nodes.
 Icon getOpenIcon()
          Returns the icon displayed for non-leaf nodes that are open (expanded).
 Dimension getPreferredSize()
          Returns the preferred size of the cell.
 Color getTextNonSelectionColor()
          Returns the text color for tree cells that are not selected.
 Color getTextSelectionColor()
          Returns the text color for tree cells that are selected.
 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.
 void paint(Graphics g)
          Paints the value.
 void repaint(long tm, int x, int y, int width, int height)
          For performance reasons, this method is overridden to do nothing.
 void repaint(Rectangle area)
          For performance reasons, this method is overridden to do nothing.
 void revalidate()
          For performance reasons, this method is overridden to do nothing.
 void setBackground(Color c)
          Sets the background color.
 void setBackgroundNonSelectionColor(Color c)
          Sets the background color for tree cells that are not selected.
 void setBackgroundSelectionColor(Color c)
          Sets the background color for tree cells that are selected.
 void setBorderSelectionColor(Color c)
          Sets the border color for tree cells that are selected.
 void setClosedIcon(Icon icon)
          Sets the icon to be displayed for non-leaf nodes that are closed.
 void setFont(Font f)
          Sets the font.
 void setLeafIcon(Icon icon)
          Sets the icon to be displayed for leaf nodes.
 void setOpenIcon(Icon icon)
          Sets the icon to be displayed for non-leaf nodes that are open (expanded).
 void setTextNonSelectionColor(Color c)
          Sets the text color for tree cells that are not selected.
 void setTextSelectionColor(Color c)
          Sets the text color for tree cells that are selected.
 void validate()
          For performance reasons, this method is overridden to do nothing.
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

selected

protected boolean selected
A flag indicating the current selection status.


hasFocus

protected boolean hasFocus
A flag indicating the current focus status.


closedIcon

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

See Also:
setClosedIcon(Icon)

leafIcon

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

See Also:
setLeafIcon(Icon)

openIcon

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

See Also:
setOpenIcon(Icon)

textSelectionColor

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

See Also:
setTextSelectionColor(Color)

textNonSelectionColor

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

See Also:
setTextNonSelectionColor(Color)

backgroundSelectionColor

protected Color backgroundSelectionColor
The background color for selected cells.

See Also:
setBackgroundSelectionColor(Color)

backgroundNonSelectionColor

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

See Also:
setBackgroundNonSelectionColor(Color)

borderSelectionColor

protected Color borderSelectionColor
The border color for selected tree cells.

See Also:
setBorderSelectionColor(Color)
Constructor Detail

DefaultTreeCellRenderer

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

Method Detail

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 LookAndFeel using the key Tree.openIcon.

Returns:
The default icon.

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 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 LookAndFeel using the key Tree.leafIcon.

Returns:
The default icon.

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()

getOpenIcon

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

Returns:
The open icon (possibly null).
See Also:
setOpenIcon(Icon)

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()

getClosedIcon

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

Returns:
The closed icon (possibly null).
See Also:
setClosedIcon(Icon)

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()

getLeafIcon

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

Returns:
The leaf icon (possibly null).
See Also:
setLeafIcon(Icon)

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()

getTextSelectionColor

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

Returns:
The text color for tree cells that are selected.
See Also:
setTextSelectionColor(Color)

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()

getTextNonSelectionColor

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

Returns:
The background color for tree cells that are not selected.
See Also:
#setTextgroundNonSelectionColor(Color)

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()

getBackgroundSelectionColor

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

Returns:
The background color for tree cells that are selected.
See Also:
setBackgroundSelectionColor(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()

getBackgroundNonSelectionColor

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

Returns:
The background color for tree cells that are not selected.
See Also:
setBackgroundNonSelectionColor(Color)

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()

getBorderSelectionColor

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

Returns:
The border color for tree cells that are selected.
See Also:
setBorderSelectionColor(Color)

setFont

public void setFont(Font f)
Sets the font.

Overrides:
setFont in class JLabel
Parameters:
f - the font.
See Also:
getFont()

setBackground

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

Overrides:
setBackground in class JComponent
Parameters:
c - the color.
See Also:
Component.getBackground()

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.

Specified by:
getTreeCellRendererComponent in interface TreeCellRenderer
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.

getFont

public Font getFont()
Returns the current font.

Specified by:
getFont in interface MenuContainer
Overrides:
getFont in class Component
Returns:
The current font.
See Also:
setFont(Font)

paint

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

Overrides:
paint in class JComponent
Parameters:
g - the graphics device.
See Also:
JComponent.paintImmediately(Rectangle)

getPreferredSize

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

Overrides:
getPreferredSize in class JComponent
Returns:
The preferred size of the cell.
See Also:
Component.setPreferredSize(java.awt.Dimension), Component.getPreferredSize(), Component.isPreferredSizeSet(), ComponentUI.getPreferredSize(JComponent)

validate

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

Overrides:
validate in class Container
See Also:
Component.invalidate(), Component.doLayout(), LayoutManager, Container.validate()

revalidate

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

Overrides:
revalidate in class JComponent

repaint

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

Overrides:
repaint in class JComponent
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
See Also:
Component.update(Graphics)

repaint

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

Overrides:
repaint in class JComponent
Parameters:
area - the area to repaint.

firePropertyChange

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

Overrides:
firePropertyChange in class Component
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.

Overrides:
firePropertyChange in class Component
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.

Overrides:
firePropertyChange in class Component
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.

Overrides:
firePropertyChange in class Component
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.

Overrides:
firePropertyChange in class JComponent
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.

Overrides:
firePropertyChange in class Component
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.

Overrides:
firePropertyChange in class Component
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.

Overrides:
firePropertyChange in class Component
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.

Overrides:
firePropertyChange in class JComponent
Parameters:
name - the property name.
oldValue - the old value.
newValue - the new value.