public class IlvDefaultTreeCellRenderer extends DefaultTreeCellRenderer
IlvDefaultTreeCellRenderer
is an extension of the Swing
DefaultTreeCellRenderer
class that provides the following
additional capabilities:
JTree
and DefaultTreeCellRenderer
classes.
JTree
computes its preferred size from the preferred sizes of
all its cell renderers. The preferred width of the tree will always be the
maximum preferred width of all its cell renderers, plus some additional space
for the expand/collapse icons, nested indentation, and so on. Similarly, the
preferred height of the tree will be the sum of the preferred heights of all
its cell renderers. However, if an explicit row height is set on the tree,
the tree uses it to calculate its preferred height instead. Because
DefaultTreeCellRenderer
is a JLabel
, it computes
its preferred size from the font and string it is displaying. Immediately
before a tree renders a cell, the tree explicitly sizes the renderer to the
renderer's preferred size.
When a JTree
is placed in a default JScrollPane
, the
scrollpane sizes the tree to its preferred size. From the tree's perspective,
all of its cells are visible. The scrollpane can then position the tree so
any portion is visible in the viewport. Cells that are positioned outside of
the viewport appear truncated at the viewport edges. When a JTree
is placed in another type of container that does not observe the tree's
preferred size, rendering issues may arise. If the tree is sized to be
narrower than its preferred width, the tree will still size each
DefaultTreeCellRenderer
to the renderer's preferred width and
the cell will appear truncated at the container's right edge.
This class provides an alternative behavior in this last case. If
auto-width
is enabled (it is by default), the
renderer will extend or shrink its right edge to match the right edge of the
tree. If the tree is narrower than the preferred width of the renderer, the
renderer will use the standard JLabel
technique of appending
ellipses (i.e. "...") to the truncated text. This provides a better
appearance than merely truncating the text rendition, possibly in
mid-letter.
JLabel.AccessibleJLabel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
backgroundNonSelectionColor, backgroundSelectionColor, borderSelectionColor, closedIcon, hasFocus, leafIcon, openIcon, selected, textNonSelectionColor, textSelectionColor
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
IlvDefaultTreeCellRenderer()
Creates a new
IlvDefaultTreeCellRenderer . |
Modifier and Type | Method and Description |
---|---|
void |
addNotify()
Notifies this component that it now has a parent component.
|
Font |
getFont()
Returns the font of the renderer.
|
Dimension |
getPreferredSize()
Returns the preferred size of the renderer.
|
String |
getToolTipText()
Returns the tooltip string for the renderer.
|
boolean |
isAutoWidthFromTree()
Returns whether the renderer sets its width to the width of the tree.
|
void |
paint(Graphics g)
Paints the rendered value.
|
void |
setAutoWidthFromTree(boolean enable)
Sets whether the renderer sets its width to the width of the tree.
|
void |
setBounds(int x,
int y,
int w,
int h)
Moves and resizes this component.
|
firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackgroundNonSelectionColor, getBackgroundSelectionColor, getBorderSelectionColor, getClosedIcon, getDefaultClosedIcon, getDefaultLeafIcon, getDefaultOpenIcon, getLeafIcon, getOpenIcon, getTextNonSelectionColor, getTextSelectionColor, getTreeCellRendererComponent, invalidate, repaint, repaint, repaint, revalidate, setBackground, setBackgroundNonSelectionColor, setBackgroundSelectionColor, setBorderSelectionColor, setClosedIcon, setFont, setLeafIcon, setOpenIcon, setTextNonSelectionColor, setTextSelectionColor, updateUI, validate
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
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, 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, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
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, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validateTree
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, 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, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public IlvDefaultTreeCellRenderer()
IlvDefaultTreeCellRenderer
.public boolean isAutoWidthFromTree()
true
. See the class
implementation notes for more information.setAutoWidthFromTree(boolean)
public void setAutoWidthFromTree(boolean enable)
true
. See the class
implementation notes for more information.enable
- Set true
to enable auto-width mode or
false
to disable and revert to standard DefaultTreeCellRenderer
behavior.isAutoWidthFromTree()
public void setBounds(int x, int y, int w, int h)
JTree
immediately before it asks the renderer to paint. This
method is overridden to support auto-width
mode
. See the class implementation notes for more
information.public Dimension getPreferredSize()
getPreferredSize
in class DefaultTreeCellRenderer
public void paint(Graphics g)
auto-width mode
. See the class
implementation notes for more information.paint
in class DefaultTreeCellRenderer
g
- The graphics context to use for painting.public void addNotify()
auto-width mode
. See
the class implementation notes for more information.addNotify
in class JComponent
public Font getFont()
JTree
is returned.
This method is overridden to fix
JavaSoft
bug 4373575.getFont
in interface MenuContainer
getFont
in class DefaultTreeCellRenderer
public String getToolTipText()
setToolTipText
method. If no tooltip has been explicitly set, then this method returns
the text value being rendered.getToolTipText
in class JComponent
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.