Class MetalTreeUI
java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.TreeUI
javax.swing.plaf.basic.BasicTreeUI
javax.swing.plaf.metal.MetalTreeUI
The metal look and feel implementation of
TreeUI.
MetalTreeUI allows for configuring how to
visually render the spacing and delineation between nodes. The following
hints are supported:
| Hint | Description |
|---|---|
| Angled | A line is drawn connecting the child to the parent. For handling of
the root node refer to JTree.setRootVisible(boolean) and
JTree.setShowsRootHandles(boolean).
|
| Horizontal | A horizontal line is drawn dividing the children of the root node. |
| None | Do not draw any visual indication between nodes. |
As it is typically impractical to obtain the TreeUI from
the JTree and cast to an instance of MetalTreeUI
you enable this property via the client property
JTree.lineStyle. For example, to switch to
Horizontal style you would do:
tree.putClientProperty("JTree.lineStyle", "Horizontal");
The default is Angled.
-
Nested Class Summary
Nested classes/interfaces inherited from class BasicTreeUI
BasicTreeUI.CellEditorHandler, BasicTreeUI.ComponentHandler, BasicTreeUI.FocusHandler, BasicTreeUI.KeyHandler, BasicTreeUI.MouseHandler, BasicTreeUI.MouseInputHandler, BasicTreeUI.NodeDimensionsHandler, BasicTreeUI.PropertyChangeHandler, BasicTreeUI.SelectionModelPropertyChangeHandler, BasicTreeUI.TreeCancelEditingAction, BasicTreeUI.TreeExpansionHandler, BasicTreeUI.TreeHomeAction, BasicTreeUI.TreeIncrementAction, BasicTreeUI.TreeModelHandler, BasicTreeUI.TreePageAction, BasicTreeUI.TreeSelectionHandler, BasicTreeUI.TreeToggleAction, BasicTreeUI.TreeTraverseAction -
Field Summary
Fields inherited from class BasicTreeUI
cellEditor, collapsedIcon, createdCellEditor, createdRenderer, currentCellRenderer, depthOffset, drawingCache, editingComponent, editingPath, editingRow, editorHasDifferentSize, expandedIcon, largeModel, lastSelectedRow, leftChildIndent, nodeDimensions, preferredMinSize, preferredSize, rendererPane, rightChildIndent, stopEditingInCompleteEditing, totalChildIndent, tree, treeModel, treeSelectionModel, treeState, validCachedPreferredSize -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ComponentUIConstructs theMetalTreeUI.protected voiddecodeLineStyle(Object lineStyleFlag) Converts between the string passed into the client property and the internal representation (currently and int)protected intThe horizontal element of legs between nodes starts at the right of the left-hand side of the child node by default.voidConfigures the specified component appropriately for the look and feel.protected booleanisLocationInExpandControl(int row, int rowLevel, int mouseX, int mouseY) Returnstrueif a point with X coordinatemouseXand Y coordinatemouseYis in expanded control.voidpaint(Graphics g, JComponent c) Paints the specified component appropriately for the look and feel.protected voidpaintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) Paints the horizontal part of the leg.protected voidPaints the horizontal separators.protected voidpaintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path) Paints the vertical part of the leg.voidReverses configuration which was done on the specified component duringinstallUI.Methods inherited from class BasicTreeUI
cancelEditing, checkForClickInExpandControl, completeEditing, completeEditing, completeUIInstall, completeUIUninstall, configureLayoutCache, createCellEditorListener, createCellRendererPane, createComponentListener, createDefaultCellEditor, createDefaultCellRenderer, createFocusListener, createKeyListener, createLayoutCache, createMouseListener, createNodeDimensions, createPropertyChangeListener, createSelectionModelPropertyChangeListener, createTreeExpansionListener, createTreeModelListener, createTreeSelectionListener, drawCentered, drawDashedHorizontalLine, drawDashedVerticalLine, ensureRowsAreVisible, getBaseline, getBaselineResizeBehavior, getCellEditor, getCellRenderer, getClosestPathForLocation, getCollapsedIcon, getDropLineRect, getEditingPath, getExpandedIcon, getHashColor, getLastChildPath, getLeadSelectionRow, getLeftChildIndent, getMaximumSize, getMinimumSize, getModel, getPathBounds, getPathForRow, getPreferredMinSize, getPreferredSize, getPreferredSize, getRightChildIndent, getRowCount, getRowForPath, getRowHeight, getRowX, getSelectionModel, getShowsRootHandles, getVerticalLegBuffer, handleExpandControlClick, installComponents, installDefaults, installKeyboardActions, installListeners, isDropLine, isEditable, isEditing, isLargeModel, isLeaf, isLocationInExpandControl, isMultiSelectEvent, isRootVisible, isToggleEvent, isToggleSelectionEvent, paintDropLine, paintExpandControl, paintHorizontalLine, paintRow, paintVerticalLine, pathWasCollapsed, pathWasExpanded, prepareForUIInstall, prepareForUIUninstall, selectPathForEvent, setCellEditor, setCellRenderer, setCollapsedIcon, setEditable, setExpandedIcon, setHashColor, setLargeModel, setLeftChildIndent, setModel, setPreferredMinSize, setRightChildIndent, setRootVisible, setRowHeight, setSelectionModel, setShowsRootHandles, shouldPaintExpandControl, startEditing, startEditingAtPath, stopEditing, toggleExpandState, uninstallComponents, uninstallDefaults, uninstallKeyboardActions, uninstallListeners, updateCachedPreferredSize, updateCellEditor, updateDepthOffset, updateExpandedDescendants, updateLayoutCacheExpandedNodes, updateLeadSelectionRow, updateRenderer, updateSizeMethods inherited from class ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, update
-
Constructor Details
-
MetalTreeUI
public MetalTreeUI()Constructs theMetalTreeUI.
-
-
Method Details
-
createUI
Constructs theMetalTreeUI.- Parameters:
x- a component- Returns:
- the instance of the
MetalTreeUI
-
getHorizontalLegBuffer
protected int getHorizontalLegBuffer()Description copied from class:BasicTreeUIThe horizontal element of legs between nodes starts at the right of the left-hand side of the child node by default. This method makes the leg end before that.- Overrides:
getHorizontalLegBufferin classBasicTreeUI- Returns:
- the horizontal leg buffer
-
installUI
Description copied from class:ComponentUIConfigures the specified component appropriately for the look and feel. This method is invoked when theComponentUIinstance is being installed as the UI delegate on the specified component. This method should completely configure the component for the look and feel, including the following:- Install default property values for color, fonts, borders, icons, opacity, etc. on the component. Whenever possible, property values initialized by the client program should not be overridden.
- Install a
LayoutManageron the component if necessary. - Create/add any required sub-components to the component.
- Create/install event listeners on the component.
- Create/install a
PropertyChangeListeneron the component in order to detect and respond to component property changes appropriately. - Install keyboard UI (mnemonics, traversal, etc.) on the component.
- Initialize any appropriate instance data.
- Overrides:
installUIin classBasicTreeUI- Parameters:
c- the component where this UI delegate is being installed- See Also:
-
uninstallUI
Description copied from class:ComponentUIReverses configuration which was done on the specified component duringinstallUI. This method is invoked when thisUIComponentinstance is being removed as the UI delegate for the specified component. This method should undo the configuration performed ininstallUI, being careful to leave theJComponentinstance in a clean state (no extraneous listeners, look-and-feel-specific property objects, etc.). This should include the following:- Remove any UI-set borders from the component.
- Remove any UI-set layout managers on the component.
- Remove any UI-added sub-components from the component.
- Remove any UI-added event/property listeners from the component.
- Remove any UI-installed keyboard UI from the component.
- Nullify any allocated instance data objects to allow for GC.
- Overrides:
uninstallUIin classBasicTreeUI- Parameters:
c- the component from which this UI delegate is being removed; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components- See Also:
-
decodeLineStyle
Converts between the string passed into the client property and the internal representation (currently and int)- Parameters:
lineStyleFlag- a flag
-
isLocationInExpandControl
protected boolean isLocationInExpandControl(int row, int rowLevel, int mouseX, int mouseY) Returnstrueif a point with X coordinatemouseXand Y coordinatemouseYis in expanded control.- Parameters:
row- a rowrowLevel- a row levelmouseX- X coordinatemouseY- Y coordinate- Returns:
trueif a point with X coordinatemouseXand Y coordinatemouseYis in expanded control.
-
paint
Description copied from class:ComponentUIPaints the specified component appropriately for the look and feel. This method is invoked from theComponentUI.updatemethod when the specified component is being painted. Subclasses should override this method and use the specifiedGraphicsobject to render the content of the component.- Overrides:
paintin classBasicTreeUI- Parameters:
g- theGraphicscontext in which to paintc- the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components- See Also:
-
paintHorizontalSeparators
Paints the horizontal separators.- Parameters:
g- an instance ofGraphicsc- a component
-
paintVerticalPartOfLeg
protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path) Description copied from class:BasicTreeUIPaints the vertical part of the leg. The receiver should NOT modifyclipBounds,insets.- Overrides:
paintVerticalPartOfLegin classBasicTreeUI- Parameters:
g- a graphics contextclipBounds- a clipped rectangleinsets- insetspath- a tree path
-
paintHorizontalPartOfLeg
protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) Description copied from class:BasicTreeUIPaints the horizontal part of the leg. The receiver should NOT modifyclipBounds, orinsets.NOTE:
parentRowcan be -1 if the root is not visible.- Overrides:
paintHorizontalPartOfLegin classBasicTreeUI- Parameters:
g- a graphics contextclipBounds- a clipped rectangleinsets- insetsbounds- a bounding rectanglepath- a tree pathrow- a rowisExpanded-trueif the path is expandedhasBeenExpanded-trueif the path has been expandedisLeaf-trueif the path is leaf
-