- java.lang.Object
-
- javax.swing.plaf.ComponentUI
-
- javax.swing.plaf.TreeUI
-
- javax.swing.plaf.basic.BasicTreeUI
-
- Direct Known Subclasses:
- MetalTreeUI, SynthTreeUI
public class BasicTreeUI extends TreeUI
The basic L&F for a hierarchical data structure.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description classBasicTreeUI.CellEditorHandlerListener responsible for getting cell editing events and updating the tree accordingly.classBasicTreeUI.ComponentHandlerUpdates the preferred size when scrolling (if necessary).classBasicTreeUI.FocusHandlerRepaints the lead selection row when focus is lost/gained.classBasicTreeUI.KeyHandlerThis is used to get mutliple key down events to appropriately generate events.classBasicTreeUI.MouseHandlerTreeMouseListener is responsible for updating the selection based on mouse events.classBasicTreeUI.MouseInputHandlerMouseInputHandler handles passing all mouse events, including mouse motion events, until the mouse is released to the destination it is constructed with.classBasicTreeUI.NodeDimensionsHandlerClass responsible for getting size of node, method is forwarded to BasicTreeUI method.classBasicTreeUI.PropertyChangeHandlerPropertyChangeListener for the tree.classBasicTreeUI.SelectionModelPropertyChangeHandlerListener on the TreeSelectionModel, resets the row selection if any of the properties of the model change.classBasicTreeUI.TreeCancelEditingActionActionListener that invokes cancelEditing when action performed.classBasicTreeUI.TreeExpansionHandlerUpdates the TreeState in response to nodes expanding/collapsing.classBasicTreeUI.TreeHomeActionTreeHomeAction is used to handle end/home actions.classBasicTreeUI.TreeIncrementActionTreeIncrementAction is used to handle up/down actions.classBasicTreeUI.TreeModelHandlerForwards all TreeModel events to the TreeState.classBasicTreeUI.TreePageActionTreePageAction handles page up and page down events.classBasicTreeUI.TreeSelectionHandlerListens for changes in the selection model and updates the display accordingly.classBasicTreeUI.TreeToggleActionFor the first selected row expandedness will be toggled.classBasicTreeUI.TreeTraverseActionTreeTraverseActionis the action used for left/right keys.
-
Field Summary
Fields Modifier and Type Field and Description protected TreeCellEditorcellEditorEditor for the tree.protected IconcollapsedIconprotected booleancreatedCellEditorSet to true if editor that is currently in the tree was created by this instance.protected booleancreatedRendererSet to true if the renderer that is currently in the tree was created by this instance.protected TreeCellRenderercurrentCellRendererRenderer that is being used to do the actual cell drawing.protected intdepthOffsetHow much the depth should be offset to properly calculate x locations.protected Hashtable<TreePath,Boolean>drawingCacheUsed for minimizing the drawing of vertical lines.protected ComponenteditingComponentWhen editing, this will be the Component that is doing the actual editing.protected TreePatheditingPathPath that is being edited.protected inteditingRowRow that is being edited.protected booleaneditorHasDifferentSizeSet to true if the editor has a different size than the renderer.protected IconexpandedIconprotected booleanlargeModelTrue if doing optimizations for a largeModel.protected intlastSelectedRowIndex of the row that was last selected.protected intleftChildIndentDistance between left margin and where vertical dashes will be drawn.protected AbstractLayoutCache.NodeDimensionsnodeDimensionsReponsible for telling the TreeState the size needed for a node.protected DimensionpreferredMinSizeMinimum preferred size.protected DimensionpreferredSizeSize needed to completely display all the nodes.protected CellRendererPanerendererPaneUsed to paint the TreeCellRenderer.protected intrightChildIndentDistance to add to leftChildIndent to determine where cell contents will be drawn.protected booleanstopEditingInCompleteEditingSet to false when editing and shouldSelectCell() returns true meaning the node should be selected before editing, used in completeEditing.protected inttotalChildIndentTotal distance that will be indented.protected JTreetreeComponent that we're going to be drawing into.protected TreeModeltreeModelUsed to determine what to display.protected TreeSelectionModeltreeSelectionModelModel maintaing the selection.protected AbstractLayoutCachetreeStateObject responsible for handling sizing and expanded issues.protected booleanvalidCachedPreferredSizeIs the preferredSize valid?
-
Constructor Summary
Constructors Constructor and Description BasicTreeUI()
-
Method Summary
Methods Modifier and Type Method and Description voidcancelEditing(JTree tree)Cancels the current editing session.protected voidcheckForClickInExpandControl(TreePath path, int mouseX, int mouseY)If themouseXandmouseYare in the expand/collapse region of therow, this will toggle the row.protected voidcompleteEditing()Messages to stop the editing session.protected voidcompleteEditing(boolean messageStop, boolean messageCancel, boolean messageTree)Stops the editing session.protected voidcompleteUIInstall()Invoked from installUI after all the defaults/listeners have been installed.protected voidcompleteUIUninstall()protected voidconfigureLayoutCache()Resets the TreeState instance based on the tree we're providing the look and feel for.protected CellEditorListenercreateCellEditorListener()Creates a listener to handle events from the current editor.protected CellRendererPanecreateCellRendererPane()Returns the renderer pane that renderer components are placed in.protected ComponentListenercreateComponentListener()Creates and returns a new ComponentHandler.protected TreeCellEditorcreateDefaultCellEditor()Creates a default cell editor.protected TreeCellRenderercreateDefaultCellRenderer()Returns the default cell renderer that is used to do the stamping of each node.protected FocusListenercreateFocusListener()Creates a listener that is responsible for updating the display when focus is lost/gained.protected KeyListenercreateKeyListener()Creates the listener reponsible for getting key events from the tree.protected AbstractLayoutCachecreateLayoutCache()Creates the object responsible for managing what is expanded, as well as the size of nodes.protected MouseListenercreateMouseListener()Creates the listener responsible for updating the selection based on mouse events.protected AbstractLayoutCache.NodeDimensionscreateNodeDimensions()Creates an instance of NodeDimensions that is able to determine the size of a given node in the tree.protected PropertyChangeListenercreatePropertyChangeListener()Creates a listener that is responsible that updates the UI based on how the tree changes.protected PropertyChangeListenercreateSelectionModelPropertyChangeListener()Creates the listener responsible for getting property change events from the selection model.protected TreeExpansionListenercreateTreeExpansionListener()Creates and returns the object responsible for updating the treestate when nodes expanded state changes.protected TreeModelListenercreateTreeModelListener()Returns a listener that can update the tree when the model changes.protected TreeSelectionListenercreateTreeSelectionListener()Creates the listener that updates the display based on selection change methods.static ComponentUIcreateUI(JComponent x)protected voiddrawCentered(Component c, Graphics graphics, Icon icon, int x, int y)protected voiddrawDashedHorizontalLine(Graphics g, int y, int x1, int x2)protected voiddrawDashedVerticalLine(Graphics g, int x, int y1, int y2)protected voidensureRowsAreVisible(int beginRow, int endRow)Ensures that the rows identified by beginRow through endRow are visible.intgetBaseline(JComponent c, int width, int height)Returns the baseline.Component.BaselineResizeBehaviorgetBaselineResizeBehavior(JComponent c)Returns an enum indicating how the baseline of the component changes as the size changes.protected TreeCellEditorgetCellEditor()protected TreeCellRenderergetCellRenderer()Return currentCellRenderer, which will either be the trees renderer, or defaultCellRenderer, which ever wasn't null.TreePathgetClosestPathForLocation(JTree tree, int x, int y)Returns the path to the node that is closest to x,y.IcongetCollapsedIcon()protected RectanglegetDropLineRect(JTree.DropLocation loc)Returns a ubounding box for the drop line.TreePathgetEditingPath(JTree tree)Returns the path to the element that is being edited.IcongetExpandedIcon()protected ColorgetHashColor()protected intgetHorizontalLegBuffer()The horizontal element of legs between nodes starts at the right of the left-hand side of the child node by default.protected TreePathgetLastChildPath(TreePath parent)Returns a path to the last child ofparent.protected intgetLeadSelectionRow()Returns the lead row of the selection.intgetLeftChildIndent()DimensiongetMaximumSize(JComponent c)Returns the maximum size for this component, which will be the preferred size if the instance is currently in a JTree, or 0, 0.DimensiongetMinimumSize(JComponent c)Returns the minimum size for this component.protected TreeModelgetModel()RectanglegetPathBounds(JTree tree, TreePath path)Returns the Rectangle enclosing the label portion that the last item in path will be drawn into.TreePathgetPathForRow(JTree tree, int row)Returns the path for passed in row.DimensiongetPreferredMinSize()Returns the minimum preferred size.DimensiongetPreferredSize(JComponent c)Returns the preferred size to properly display the tree, this is a cover method for getPreferredSize(c, true).DimensiongetPreferredSize(JComponent c, boolean checkConsistency)Returns the preferred size to represent the tree in c.intgetRightChildIndent()intgetRowCount(JTree tree)Returns the number of rows that are being displayed.intgetRowForPath(JTree tree, TreePath path)Returns the row that the last item identified in path is visible at.protected intgetRowHeight()protected intgetRowX(int row, int depth)Returns the location, along the x-axis, to render a particular row at.protected TreeSelectionModelgetSelectionModel()protected booleangetShowsRootHandles()protected intgetVerticalLegBuffer()The vertical element of legs between nodes starts at the bottom of the parent node by default.protected voidhandleExpandControlClick(TreePath path, int mouseX, int mouseY)Messaged when the user clicks the particular row, this invokes toggleExpandState.protected voidinstallComponents()Intalls the subcomponents of the tree, which is the renderer pane.protected voidinstallDefaults()protected voidinstallKeyboardActions()protected voidinstallListeners()voidinstallUI(JComponent c)Configures the specified component appropriately for the look and feel.protected booleanisDropLine(JTree.DropLocation loc)Tells if aDropLocationshould be indicated by a line between nodes.protected booleanisEditable()booleanisEditing(JTree tree)Returns true if the tree is being edited.protected booleanisLargeModel()protected booleanisLeaf(int row)protected booleanisLocationInExpandControl(TreePath path, int mouseX, int mouseY)Returns true ifmouseXandmouseYfall in the area of row that is used to expand/collapse the node and the node atrowdoes not represent a leaf.protected booleanisMultiSelectEvent(MouseEvent event)Returning true signifies a mouse event on the node should select from the anchor point.protected booleanisRootVisible()protected booleanisToggleEvent(MouseEvent event)Returning true indicates the row under the mouse should be toggled based on the event.protected booleanisToggleSelectionEvent(MouseEvent event)Returning true signifies a mouse event on the node should toggle the selection of only the row under mouse.voidpaint(Graphics g, JComponent c)Paints the specified component appropriately for the look and feel.protected voidpaintDropLine(Graphics g)Paints the drop line.protected voidpaintExpandControl(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)Paints the expand (toggle) part of a row.protected voidpaintHorizontalLine(Graphics g, JComponent c, int y, int left, int right)Paints a horizontal line.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 voidpaintRow(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)Paints the renderer part of a row.protected voidpaintVerticalLine(Graphics g, JComponent c, int x, int top, int bottom)Paints a vertical line.protected voidpaintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path)Paints the vertical part of the leg.protected voidpathWasCollapsed(TreePath path)Messaged from the VisibleTreeNode after it has collapsed.protected voidpathWasExpanded(TreePath path)Messaged from the VisibleTreeNode after it has been expanded.protected voidprepareForUIInstall()Invoked after thetreeinstance variable has been set, but before any defaults/listeners have been installed.protected voidprepareForUIUninstall()protected voidselectPathForEvent(TreePath path, MouseEvent event)Messaged to update the selection based on a MouseEvent over a particular row.protected voidsetCellEditor(TreeCellEditor editor)Sets the cell editor.protected voidsetCellRenderer(TreeCellRenderer tcr)Sets the TreeCellRenderer totcr.voidsetCollapsedIcon(Icon newG)protected voidsetEditable(boolean newValue)Configures the receiver to allow, or not allow, editing.voidsetExpandedIcon(Icon newG)protected voidsetHashColor(Color color)protected voidsetLargeModel(boolean largeModel)Updates the componentListener, if necessary.voidsetLeftChildIndent(int newAmount)protected voidsetModel(TreeModel model)Sets the TreeModel.voidsetPreferredMinSize(Dimension newSize)Sets the preferred minimum size.voidsetRightChildIndent(int newAmount)protected voidsetRootVisible(boolean newValue)Sets the root to being visible.protected voidsetRowHeight(int rowHeight)Sets the row height, this is forwarded to the treeState.protected voidsetSelectionModel(TreeSelectionModel newLSM)Resets the selection model.protected voidsetShowsRootHandles(boolean newValue)Determines whether the node handles are to be displayed.protected booleanshouldPaintExpandControl(TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)Returns true if the expand (toggle) control should be drawn for the specified row.protected booleanstartEditing(TreePath path, MouseEvent event)Will start editing for node if there is a cellEditor and shouldSelectCell returns true.voidstartEditingAtPath(JTree tree, TreePath path)Selects the last item in path and tries to edit it.booleanstopEditing(JTree tree)Stops the current editing session.protected voidtoggleExpandState(TreePath path)Expands path if it is not expanded, or collapses row if it is expanded.protected voiduninstallComponents()Uninstalls the renderer pane.protected voiduninstallDefaults()protected voiduninstallKeyboardActions()protected voiduninstallListeners()voiduninstallUI(JComponent c)Reverses configuration which was done on the specified component duringinstallUI.protected voidupdateCachedPreferredSize()Updates thepreferredSizeinstance variable, which is returned fromgetPreferredSize().protected voidupdateCellEditor()Updates the cellEditor based on the editability of the JTree that we're contained in.protected voidupdateDepthOffset()Updates how much each depth should be offset by.protected voidupdateExpandedDescendants(TreePath path)Updates the expanded state of all the descendants ofpathby getting the expanded descendants from the tree and forwarding to the tree state.protected voidupdateLayoutCacheExpandedNodes()Makes all the nodes that are expanded in JTree expanded in LayoutCache.protected voidupdateLeadSelectionRow()Updates the lead row of the selection.protected voidupdateRenderer()Messaged from the tree we're in when the renderer has changed.protected voidupdateSize()Marks the cached size as being invalid, and messages the tree withtreeDidChange.-
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, update
-
-
-
-
Field Detail
-
collapsedIcon
protected transient Icon collapsedIcon
-
expandedIcon
protected transient Icon expandedIcon
-
leftChildIndent
protected int leftChildIndent
Distance between left margin and where vertical dashes will be drawn.
-
rightChildIndent
protected int rightChildIndent
Distance to add to leftChildIndent to determine where cell contents will be drawn.
-
totalChildIndent
protected int totalChildIndent
Total distance that will be indented. The sum of leftChildIndent and rightChildIndent.
-
preferredMinSize
protected Dimension preferredMinSize
Minimum preferred size.
-
lastSelectedRow
protected int lastSelectedRow
Index of the row that was last selected.
-
tree
protected JTree tree
Component that we're going to be drawing into.
-
currentCellRenderer
protected transient TreeCellRenderer currentCellRenderer
Renderer that is being used to do the actual cell drawing.
-
createdRenderer
protected boolean createdRenderer
Set to true if the renderer that is currently in the tree was created by this instance.
-
cellEditor
protected transient TreeCellEditor cellEditor
Editor for the tree.
-
createdCellEditor
protected boolean createdCellEditor
Set to true if editor that is currently in the tree was created by this instance.
-
stopEditingInCompleteEditing
protected boolean stopEditingInCompleteEditing
Set to false when editing and shouldSelectCell() returns true meaning the node should be selected before editing, used in completeEditing.
-
rendererPane
protected CellRendererPane rendererPane
Used to paint the TreeCellRenderer.
-
preferredSize
protected Dimension preferredSize
Size needed to completely display all the nodes.
-
validCachedPreferredSize
protected boolean validCachedPreferredSize
Is the preferredSize valid?
-
treeState
protected AbstractLayoutCache treeState
Object responsible for handling sizing and expanded issues.
-
drawingCache
protected Hashtable<TreePath,Boolean> drawingCache
Used for minimizing the drawing of vertical lines.
-
largeModel
protected boolean largeModel
True if doing optimizations for a largeModel. Subclasses that don't support this may wish to override createLayoutCache to not return a FixedHeightLayoutCache instance.
-
nodeDimensions
protected AbstractLayoutCache.NodeDimensions nodeDimensions
Reponsible for telling the TreeState the size needed for a node.
-
treeModel
protected TreeModel treeModel
Used to determine what to display.
-
treeSelectionModel
protected TreeSelectionModel treeSelectionModel
Model maintaing the selection.
-
depthOffset
protected int depthOffset
How much the depth should be offset to properly calculate x locations. This is based on whether or not the root is visible, and if the root handles are visible.
-
editingComponent
protected Component editingComponent
When editing, this will be the Component that is doing the actual editing.
-
editingPath
protected TreePath editingPath
Path that is being edited.
-
editingRow
protected int editingRow
Row that is being edited. Should only be referenced if editingComponent is not null.
-
editorHasDifferentSize
protected boolean editorHasDifferentSize
Set to true if the editor has a different size than the renderer.
-
-
Method Detail
-
createUI
public static ComponentUI createUI(JComponent x)
-
getHashColor
protected Color getHashColor()
-
setHashColor
protected void setHashColor(Color color)
-
setLeftChildIndent
public void setLeftChildIndent(int newAmount)
-
getLeftChildIndent
public int getLeftChildIndent()
-
setRightChildIndent
public void setRightChildIndent(int newAmount)
-
getRightChildIndent
public int getRightChildIndent()
-
setExpandedIcon
public void setExpandedIcon(Icon newG)
-
getExpandedIcon
public Icon getExpandedIcon()
-
setCollapsedIcon
public void setCollapsedIcon(Icon newG)
-
getCollapsedIcon
public Icon getCollapsedIcon()
-
setLargeModel
protected void setLargeModel(boolean largeModel)
Updates the componentListener, if necessary.
-
isLargeModel
protected boolean isLargeModel()
-
setRowHeight
protected void setRowHeight(int rowHeight)
Sets the row height, this is forwarded to the treeState.
-
getRowHeight
protected int getRowHeight()
-
setCellRenderer
protected void setCellRenderer(TreeCellRenderer tcr)
Sets the TreeCellRenderer totcr. This invokesupdateRenderer.
-
getCellRenderer
protected TreeCellRenderer getCellRenderer()
Return currentCellRenderer, which will either be the trees renderer, or defaultCellRenderer, which ever wasn't null.
-
setModel
protected void setModel(TreeModel model)
Sets the TreeModel.
-
getModel
protected TreeModel getModel()
-
setRootVisible
protected void setRootVisible(boolean newValue)
Sets the root to being visible.
-
isRootVisible
protected boolean isRootVisible()
-
setShowsRootHandles
protected void setShowsRootHandles(boolean newValue)
Determines whether the node handles are to be displayed.
-
getShowsRootHandles
protected boolean getShowsRootHandles()
-
setCellEditor
protected void setCellEditor(TreeCellEditor editor)
Sets the cell editor.
-
getCellEditor
protected TreeCellEditor getCellEditor()
-
setEditable
protected void setEditable(boolean newValue)
Configures the receiver to allow, or not allow, editing.
-
isEditable
protected boolean isEditable()
-
setSelectionModel
protected void setSelectionModel(TreeSelectionModel newLSM)
Resets the selection model. The appropriate listener are installed on the model.
-
getSelectionModel
protected TreeSelectionModel getSelectionModel()
-
getPathBounds
public Rectangle getPathBounds(JTree tree, TreePath path)
Returns the Rectangle enclosing the label portion that the last item in path will be drawn into. Will return null if any component in path is currently valid.- Specified by:
getPathBoundsin classTreeUI
-
getPathForRow
public TreePath getPathForRow(JTree tree, int row)
Returns the path for passed in row. If row is not visible null is returned.- Specified by:
getPathForRowin classTreeUI
-
getRowForPath
public int getRowForPath(JTree tree, TreePath path)
Returns the row that the last item identified in path is visible at. Will return -1 if any of the elements in path are not currently visible.- Specified by:
getRowForPathin classTreeUI
-
getRowCount
public int getRowCount(JTree tree)
Returns the number of rows that are being displayed.- Specified by:
getRowCountin classTreeUI
-
getClosestPathForLocation
public TreePath getClosestPathForLocation(JTree tree, int x, int y)
Returns the path to the node that is closest to x,y. If there is nothing currently visible this will return null, otherwise it'll always return a valid path. If you need to test if the returned object is exactly at x, y you should get the bounds for the returned path and test x, y against that.- Specified by:
getClosestPathForLocationin classTreeUI
-
isEditing
public boolean isEditing(JTree tree)
Returns true if the tree is being edited. The item that is being edited can be returned by getEditingPath().
-
stopEditing
public boolean stopEditing(JTree tree)
Stops the current editing session. This has no effect if the tree isn't being edited. Returns true if the editor allows the editing session to stop.- Specified by:
stopEditingin classTreeUI
-
cancelEditing
public void cancelEditing(JTree tree)
Cancels the current editing session.- Specified by:
cancelEditingin classTreeUI
-
startEditingAtPath
public void startEditingAtPath(JTree tree, TreePath path)
Selects the last item in path and tries to edit it. Editing will fail if the CellEditor won't allow it for the selected item.- Specified by:
startEditingAtPathin classTreeUI
-
getEditingPath
public TreePath getEditingPath(JTree tree)
Returns the path to the element that is being edited.- Specified by:
getEditingPathin classTreeUI
-
installUI
public void installUI(JComponent c)
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 classComponentUI- Parameters:
c- the component where this UI delegate is being installed- See Also:
ComponentUI.uninstallUI(javax.swing.JComponent),JComponent.setUI(javax.swing.plaf.ComponentUI),JComponent.updateUI()
-
prepareForUIInstall
protected void prepareForUIInstall()
Invoked after thetreeinstance variable has been set, but before any defaults/listeners have been installed.
-
completeUIInstall
protected void completeUIInstall()
Invoked from installUI after all the defaults/listeners have been installed.
-
installDefaults
protected void installDefaults()
-
installListeners
protected void installListeners()
-
installKeyboardActions
protected void installKeyboardActions()
-
installComponents
protected void installComponents()
Intalls the subcomponents of the tree, which is the renderer pane.
-
createNodeDimensions
protected AbstractLayoutCache.NodeDimensions createNodeDimensions()
Creates an instance of NodeDimensions that is able to determine the size of a given node in the tree.
-
createPropertyChangeListener
protected PropertyChangeListener createPropertyChangeListener()
Creates a listener that is responsible that updates the UI based on how the tree changes.
-
createMouseListener
protected MouseListener createMouseListener()
Creates the listener responsible for updating the selection based on mouse events.
-
createFocusListener
protected FocusListener createFocusListener()
Creates a listener that is responsible for updating the display when focus is lost/gained.
-
createKeyListener
protected KeyListener createKeyListener()
Creates the listener reponsible for getting key events from the tree.
-
createSelectionModelPropertyChangeListener
protected PropertyChangeListener createSelectionModelPropertyChangeListener()
Creates the listener responsible for getting property change events from the selection model.
-
createTreeSelectionListener
protected TreeSelectionListener createTreeSelectionListener()
Creates the listener that updates the display based on selection change methods.
-
createCellEditorListener
protected CellEditorListener createCellEditorListener()
Creates a listener to handle events from the current editor.
-
createComponentListener
protected ComponentListener createComponentListener()
Creates and returns a new ComponentHandler. This is used for the large model to mark the validCachedPreferredSize as invalid when the component moves.
-
createTreeExpansionListener
protected TreeExpansionListener createTreeExpansionListener()
Creates and returns the object responsible for updating the treestate when nodes expanded state changes.
-
createLayoutCache
protected AbstractLayoutCache createLayoutCache()
Creates the object responsible for managing what is expanded, as well as the size of nodes.
-
createCellRendererPane
protected CellRendererPane createCellRendererPane()
Returns the renderer pane that renderer components are placed in.
-
createDefaultCellEditor
protected TreeCellEditor createDefaultCellEditor()
Creates a default cell editor.
-
createDefaultCellRenderer
protected TreeCellRenderer createDefaultCellRenderer()
Returns the default cell renderer that is used to do the stamping of each node.
-
createTreeModelListener
protected TreeModelListener createTreeModelListener()
Returns a listener that can update the tree when the model changes.
-
uninstallUI
public void uninstallUI(JComponent c)
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 classComponentUI- 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:
ComponentUI.installUI(javax.swing.JComponent),JComponent.updateUI()
-
prepareForUIUninstall
protected void prepareForUIUninstall()
-
completeUIUninstall
protected void completeUIUninstall()
-
uninstallDefaults
protected void uninstallDefaults()
-
uninstallListeners
protected void uninstallListeners()
-
uninstallKeyboardActions
protected void uninstallKeyboardActions()
-
uninstallComponents
protected void uninstallComponents()
Uninstalls the renderer pane.
-
getBaseline
public int getBaseline(JComponent c, int width, int height)
Returns the baseline.- Overrides:
getBaselinein classComponentUI- Parameters:
c-JComponentbaseline is being requested forwidth- the width to get the baseline forheight- the height to get the baseline for- Returns:
- baseline or a value < 0 indicating there is no reasonable baseline
- Throws:
NullPointerException- ifcisnullIllegalArgumentException- if width or height is < 0- Since:
- 1.6
- See Also:
JComponent.getBaseline(int, int)
-
getBaselineResizeBehavior
public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
Returns an enum indicating how the baseline of the component changes as the size changes.- Overrides:
getBaselineResizeBehaviorin classComponentUI- Parameters:
c-JComponentto return baseline resize behavior for- Returns:
- an enum indicating how the baseline changes as the component size changes
- Throws:
NullPointerException- ifcisnull- Since:
- 1.6
- See Also:
JComponent.getBaseline(int, int)
-
paint
public void paint(Graphics g, JComponent c)
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 classComponentUI- 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:
ComponentUI.update(java.awt.Graphics, javax.swing.JComponent)
-
isDropLine
protected boolean isDropLine(JTree.DropLocation loc)
Tells if aDropLocationshould be indicated by a line between nodes. This is meant forjavax.swing.DropMode.INSERTandjavax.swing.DropMode.ON_OR_INSERTdrop modes.- Parameters:
loc- aDropLocation- Returns:
trueif the drop location should be shown as a line- Since:
- 1.7
-
paintDropLine
protected void paintDropLine(Graphics g)
Paints the drop line.- Parameters:
g-Graphicsobject to draw on- Since:
- 1.7
-
getDropLineRect
protected Rectangle getDropLineRect(JTree.DropLocation loc)
Returns a ubounding box for the drop line.- Parameters:
loc- aDropLocation- Returns:
- bounding box for the drop line
- Since:
- 1.7
-
paintHorizontalPartOfLeg
protected void paintHorizontalPartOfLeg(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. The receiver should NOT modifyclipBounds, orinsets.NOTE:
parentRowcan be -1 if the root is not visible.
-
paintVerticalPartOfLeg
protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path)
Paints the vertical part of the leg. The receiver should NOT modifyclipBounds,insets.
-
paintExpandControl
protected void paintExpandControl(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
Paints the expand (toggle) part of a row. The receiver should NOT modifyclipBounds, orinsets.
-
paintRow
protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
Paints the renderer part of a row. The receiver should NOT modifyclipBounds, orinsets.
-
shouldPaintExpandControl
protected boolean shouldPaintExpandControl(TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf)
Returns true if the expand (toggle) control should be drawn for the specified row.
-
paintVerticalLine
protected void paintVerticalLine(Graphics g, JComponent c, int x, int top, int bottom)
Paints a vertical line.
-
paintHorizontalLine
protected void paintHorizontalLine(Graphics g, JComponent c, int y, int left, int right)
Paints a horizontal line.
-
getVerticalLegBuffer
protected int getVerticalLegBuffer()
The vertical element of legs between nodes starts at the bottom of the parent node by default. This method makes the leg start below that.
-
getHorizontalLegBuffer
protected int getHorizontalLegBuffer()
The 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.
-
drawDashedHorizontalLine
protected void drawDashedHorizontalLine(Graphics g, int y, int x1, int x2)
-
drawDashedVerticalLine
protected void drawDashedVerticalLine(Graphics g, int x, int y1, int y2)
-
getRowX
protected int getRowX(int row, int depth)Returns the location, along the x-axis, to render a particular row at. The return value does not include any Insets specified on the JTree. This does not check for the validity of the row or depth, it is assumed to be correct and will not throw an Exception if the row or depth doesn't match that of the tree.- Parameters:
row- Row to return x location fordepth- Depth of the row- Returns:
- amount to indent the given row.
- Since:
- 1.5
-
updateLayoutCacheExpandedNodes
protected void updateLayoutCacheExpandedNodes()
Makes all the nodes that are expanded in JTree expanded in LayoutCache. This invokes updateExpandedDescendants with the root path.
-
updateExpandedDescendants
protected void updateExpandedDescendants(TreePath path)
Updates the expanded state of all the descendants ofpathby getting the expanded descendants from the tree and forwarding to the tree state.
-
getLastChildPath
protected TreePath getLastChildPath(TreePath parent)
Returns a path to the last child ofparent.
-
updateDepthOffset
protected void updateDepthOffset()
Updates how much each depth should be offset by.
-
updateCellEditor
protected void updateCellEditor()
Updates the cellEditor based on the editability of the JTree that we're contained in. If the tree is editable but doesn't have a cellEditor, a basic one will be used.
-
updateRenderer
protected void updateRenderer()
Messaged from the tree we're in when the renderer has changed.
-
configureLayoutCache
protected void configureLayoutCache()
Resets the TreeState instance based on the tree we're providing the look and feel for.
-
updateSize
protected void updateSize()
Marks the cached size as being invalid, and messages the tree withtreeDidChange.
-
updateCachedPreferredSize
protected void updateCachedPreferredSize()
Updates thepreferredSizeinstance variable, which is returned fromgetPreferredSize().For left to right orientations, the size is determined from the current AbstractLayoutCache. For RTL orientations, the preferred size becomes the width minus the minimum x position.
-
pathWasExpanded
protected void pathWasExpanded(TreePath path)
Messaged from the VisibleTreeNode after it has been expanded.
-
pathWasCollapsed
protected void pathWasCollapsed(TreePath path)
Messaged from the VisibleTreeNode after it has collapsed.
-
ensureRowsAreVisible
protected void ensureRowsAreVisible(int beginRow, int endRow)Ensures that the rows identified by beginRow through endRow are visible.
-
setPreferredMinSize
public void setPreferredMinSize(Dimension newSize)
Sets the preferred minimum size.
-
getPreferredMinSize
public Dimension getPreferredMinSize()
Returns the minimum preferred size.
-
getPreferredSize
public Dimension getPreferredSize(JComponent c)
Returns the preferred size to properly display the tree, this is a cover method for getPreferredSize(c, true).- Overrides:
getPreferredSizein classComponentUI- Parameters:
c- the component whose preferred size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components- See Also:
JComponent.getPreferredSize(),LayoutManager.preferredLayoutSize(java.awt.Container)
-
getPreferredSize
public Dimension getPreferredSize(JComponent c, boolean checkConsistency)
Returns the preferred size to represent the tree in c. If checkConsistency is true checkConsistency is messaged first.
-
getMinimumSize
public Dimension getMinimumSize(JComponent c)
Returns the minimum size for this component. Which will be the min preferred size or 0, 0.- Overrides:
getMinimumSizein classComponentUI- Parameters:
c- the component whose minimum size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components- Returns:
- a
Dimensionobject ornull - See Also:
JComponent.getMinimumSize(),LayoutManager.minimumLayoutSize(java.awt.Container),ComponentUI.getPreferredSize(javax.swing.JComponent)
-
getMaximumSize
public Dimension getMaximumSize(JComponent c)
Returns the maximum size for this component, which will be the preferred size if the instance is currently in a JTree, or 0, 0.- Overrides:
getMaximumSizein classComponentUI- Parameters:
c- the component whose maximum size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components- Returns:
- a
Dimensionobject ornull - See Also:
JComponent.getMaximumSize(),LayoutManager2.maximumLayoutSize(java.awt.Container)
-
completeEditing
protected void completeEditing()
Messages to stop the editing session. If the UI the receiver is providing the look and feel for returns true fromgetInvokesStopCellEditing, stopCellEditing will invoked on the current editor. Then completeEditing will be messaged with false, true, false to cancel any lingering editing.
-
completeEditing
protected void completeEditing(boolean messageStop, boolean messageCancel, boolean messageTree)Stops the editing session. If messageStop is true the editor is messaged with stopEditing, if messageCancel is true the editor is messaged with cancelEditing. If messageTree is true the treeModel is messaged with valueForPathChanged.
-
startEditing
protected boolean startEditing(TreePath path, MouseEvent event)
Will start editing for node if there is a cellEditor and shouldSelectCell returns true.This assumes that path is valid and visible.
-
checkForClickInExpandControl
protected void checkForClickInExpandControl(TreePath path, int mouseX, int mouseY)
If themouseXandmouseYare in the expand/collapse region of therow, this will toggle the row.
-
isLocationInExpandControl
protected boolean isLocationInExpandControl(TreePath path, int mouseX, int mouseY)
Returns true ifmouseXandmouseYfall in the area of row that is used to expand/collapse the node and the node atrowdoes not represent a leaf.
-
handleExpandControlClick
protected void handleExpandControlClick(TreePath path, int mouseX, int mouseY)
Messaged when the user clicks the particular row, this invokes toggleExpandState.
-
toggleExpandState
protected void toggleExpandState(TreePath path)
Expands path if it is not expanded, or collapses row if it is expanded. If expanding a path and JTree scrolls on expand, ensureRowsAreVisible is invoked to scroll as many of the children to visible as possible (tries to scroll to last visible descendant of path).
-
isToggleSelectionEvent
protected boolean isToggleSelectionEvent(MouseEvent event)
Returning true signifies a mouse event on the node should toggle the selection of only the row under mouse.
-
isMultiSelectEvent
protected boolean isMultiSelectEvent(MouseEvent event)
Returning true signifies a mouse event on the node should select from the anchor point.
-
isToggleEvent
protected boolean isToggleEvent(MouseEvent event)
Returning true indicates the row under the mouse should be toggled based on the event. This is invoked after checkForClickInExpandControl, implying the location is not in the expand (toggle) control
-
selectPathForEvent
protected void selectPathForEvent(TreePath path, MouseEvent event)
Messaged to update the selection based on a MouseEvent over a particular row. If the event is a toggle selection event, the row is either selected, or deselected. If the event identifies a multi selection event, the selection is updated from the anchor point. Otherwise the row is selected, and if the event specified a toggle event the row is expanded/collapsed.
-
isLeaf
protected boolean isLeaf(int row)
- Returns:
- true if the node at
rowis a leaf.
-
updateLeadSelectionRow
protected void updateLeadSelectionRow()
Updates the lead row of the selection.- Since:
- 1.7
-
getLeadSelectionRow
protected int getLeadSelectionRow()
Returns the lead row of the selection.- Returns:
- selection lead row
- Since:
- 1.7
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
08/10/2025 12:48:28 Cette version de la page est en cache (à la date du 08/10/2025 12:48:28) afin d'accélérer le traitement.Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.
Document créé le 01/09/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/swing/plaf/basic/basictreeui.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.