Top Description Inners Fields Constructors Methods
javax.swing

public Class JTree

extends JComponent
implements Scrollable, Accessible
Class Inheritance
All Implemented Interfaces
javax.accessibility.Accessible, javax.swing.Scrollable
Annotations
@JavaBean
defaultProperty:UI
description:A component that displays a set of hierarchical data as an outline.
@SwingContainer:false
@SuppressWarnings:serial
Imports
java.awt.Color, .Component, .Container, .Cursor, .Dimension, .Font, .FontMetrics, .GraphicsEnvironment, .HeadlessException, .IllegalComponentStateException, .Point, .Rectangle, java.awt.event.ActionEvent, .FocusListener, .MouseEvent, java.beans.BeanProperty, .ConstructorProperties, .JavaBean, .PropertyChangeEvent, .PropertyChangeListener, java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serial, .Serializable, java.util.Collections, .Enumeration, .Hashtable, .Locale, .Set, .Stack, .Vector, javax.accessibility.Accessible, .AccessibleAction, .AccessibleComponent, .AccessibleContext, .AccessibleRole, .AccessibleSelection, .AccessibleState, .AccessibleStateSet, .AccessibleText, .AccessibleValue, javax.swing.event.EventListenerList, .TreeExpansionEvent, .TreeExpansionListener, .TreeModelEvent, .TreeModelListener, .TreeSelectionEvent, .TreeSelectionListener, .TreeWillExpandListener, javax.swing.plaf.TreeUI, javax.swing.text.Position, javax.swing.tree.DefaultMutableTreeNode, .DefaultTreeModel, .DefaultTreeSelectionModel, .ExpandVetoException, .RowMapper, .TreeCellEditor, .TreeCellRenderer, .TreeModel, .TreeNode, .TreePath, .TreeSelectionModel, sun.awt.AWTAccessor, .AWTAccessor.MouseEventAccessor, sun.swing.SwingAccessor, .SwingUtilities2, .SwingUtilities2.Section

A control that displays a set of hierarchical data as an outline. You can find task-oriented documentation and examples of using trees in How to Use Trees, a section in The Java Tutorial.

A specific node in a tree can be identified either by a TreePath (an object that encapsulates a node and all of its ancestors), or by its display row, where each row in the display area displays one node. An expanded node is a non-leaf node (as identified by TreeModel.isLeaf(node) returning false) that will displays its children when all its ancestors are expanded. A collapsed node is one which hides them. A hidden node is one which is under a collapsed ancestor. All of a viewable nodes parents are expanded, but may or may not be displayed. A displayed node is both viewable and in the display area, where it can be seen.

The following JTree methods use "visible" to mean "displayed": The next group of JTree methods use "visible" to mean "viewable" (under an expanded parent): If you are interested in knowing when the selection changes implement the TreeSelectionListener interface and add the instance using the method addTreeSelectionListener. valueChanged will be invoked when the selection changes, that is if the user clicks twice on the same node valueChanged will only be invoked once.

If you are interested in detecting either double-click events or when a user clicks on a node, regardless of whether or not it was selected, we recommend you do the following:

 final JTree tree = ...;

 MouseListener ml = new MouseAdapter() {
     public void mousePressed(MouseEvent e) {
         int selRow = tree.getRowForLocation(e.getX(), e.getY());
         TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
         if(selRow != -1) {
             if(e.getClickCount() == 1) {
                 mySingleClick(selRow, selPath);
             }
             else if(e.getClickCount() == 2) {
                 myDoubleClick(selRow, selPath);
             }
         }
     }
 };
 tree.addMouseListener(ml);
 
NOTE: This example obtains both the path and row, but you only need to get the one you're interested in.

To use JTree to display compound nodes (for example, nodes containing both a graphic icon and text), subclass TreeCellRenderer and use setCellRenderer to tell the tree to use it. To edit such nodes, subclass TreeCellEditor and use setCellEditor.

Like all JComponent classes, you can use InputMap and ActionMap to associate an Action object with a KeyStroke and execute the action under specified conditions.

Warning

Swing is not thread safe. For more information see Swing's Threading Policy.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Authors
Rob Davis, Ray Ryan, Scott Violet
Since
1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
JTree.AccessibleJTree

This class implements accessibility support for the JTree class.

public static class
JTree.DropLocation

A subclass of TransferHandler.DropLocation representing a drop location for a JTree.

public static class
JTree.DynamicUtilTreeNode

DynamicUtilTreeNode can wrap vectors/hashtables/arrays/strings and create the appropriate children tree nodes as necessary.

protected static class
JTree.EmptySelectionModel

EmptySelectionModel is a TreeSelectionModel that does not allow anything to be selected.

protected class
JTree.TreeModelHandler

Listens to the model and updates the expandedState accordingly when nodes are removed, or changed.

protected class
JTree.TreeSelectionRedirector

Handles creating a new TreeSelectionEvent with the JTree as the source and passing it off to all the listeners.

private class

Field Summary

Modifier and TypeField and Description
public static final String
ANCHOR_SELECTION_PATH_PROPERTY

Bound property name for anchor selection path.

private TreePath
anchorPath

Anchor path.

public static final String
CELL_EDITOR_PROPERTY

Bound property name for cellEditor.

public static final String
CELL_RENDERER_PROPERTY

Bound property name for cellRenderer.

protected transient TreeCellEditor
cellEditor

Editor for the entries.

protected transient TreeCellRenderer
cellRenderer

The cell used to draw nodes.

private boolean
dragEnabled

If true, mouse presses on selections initiate a drag operation.

private transient JTree.DropLocation
dropLocation

The drop location.

private DropMode
dropMode

The drop mode for this component.

private JTree.TreeTimer
dropTimer

A timer to expand nodes during drop.

protected boolean
editable

Is the tree editable?

public static final String
EDITABLE_PROPERTY

Bound property name for editable.

private transient Stack<Stack<TreePath>>
expandedStack

Used when setExpandedState is invoked, will be a Stack of Stacks.

private transient Hashtable<TreePath, Boolean>
expandedState

Maps from TreePath to Boolean indicating whether or not the particular path is expanded.

private int
expandRow

The row to expand during DnD.

public static final String
EXPANDS_SELECTED_PATHS_PROPERTY

Bound property name for expands selected paths property

private boolean
expandsSelectedPaths

True if paths in the selection should be expanded.

public static final String
INVOKES_STOP_CELL_EDITING_PROPERTY

Bound property name for messagesStopCellEditing.

protected boolean
invokesStopCellEditing

If true, when editing is to be stopped by way of selection changing, data in tree changing or other means stopCellEditing is invoked, and changes are saved.

public static final String
LARGE_MODEL_PROPERTY

Bound property name for largeModel.

protected boolean
largeModel

Is this tree a large model?

public static final String
LEAD_SELECTION_PATH_PROPERTY

Bound property name for leadSelectionPath.

private TreePath
leadPath

Lead selection path, may not be null.

public static final String
ROOT_VISIBLE_PROPERTY

Bound property name for rootVisible.

protected boolean
rootVisible

True if the root node is displayed, false if its children are the highest visible nodes.

public static final String
ROW_HEIGHT_PROPERTY

Bound property name for rowHeight.

protected int
rowHeight

Height to use for each display row.

private boolean
public static final String
SCROLLS_ON_EXPAND_PROPERTY

Bound property name for scrollsOnExpand.

protected boolean
scrollsOnExpand

If true, when a node is expanded, as many of the descendants are scrolled to be visible.

private boolean
public static final String
SELECTION_MODEL_PROPERTY

Bound property name for selectionModel.

protected transient TreeSelectionModel
selectionModel

Models the set of selected nodes in this tree.

protected transient JTree.TreeSelectionRedirector
selectionRedirector

Creates a new event and passed it off the selectionListeners.

private boolean
settingUI

This is set to true for the life of the setUI call.

public static final String
SHOWS_ROOT_HANDLES_PROPERTY

Bound property name for showsRootHandles.

protected boolean
showsRootHandles

True if handles are displayed at the topmost level of the tree.

private boolean
private static int
TEMP_STACK_SIZE

Max number of stacks to keep around.

public static final String
TOGGLE_CLICK_COUNT_PROPERTY

Bound property name for toggleClickCount.

protected int
toggleClickCount

Number of mouse clicks before a node is expanded.

public static final String
TREE_MODEL_PROPERTY

Bound property name for treeModel.

protected transient TreeModel
treeModel

The model that defines the tree displayed by this object.

protected transient TreeModelListener
treeModelListener

Updates the expandedState.

private static final String
private transient TreeExpansionListener
uiTreeExpansionListener

When addTreeExpansionListener is invoked, and settingUI is true, this ivar gets set to the passed in Listener.

private transient boolean
updateInProgress

Flag to indicate UI update is in progress

public static final String
VISIBLE_ROW_COUNT_PROPERTY

Bound property name for visibleRowCount.

protected int
visibleRowCount

Number of rows to make visible at one time.

Inherited from javax.swing.JComponent:
DEBUG_GRAPHICS_LOADEDfocusControllerlistenerListpaintingChildTOOL_TIP_TEXT_KEYuiUNDEFINED_CONDITIONWHEN_ANCESTOR_OF_FOCUSED_COMPONENTWHEN_FOCUSEDWHEN_IN_FOCUSED_WINDOW

Constructor Summary

AccessConstructor and Description
public
JTree()

Returns a JTree with a sample model.

public
JTree(Object[]
an array of Objects
value
)

Returns a JTree with each element of the specified array as the child of a new root node which is not displayed.

public
JTree(Vector<?>
a Vector
value
)

Returns a JTree with each element of the specified Vector as the child of a new root node which is not displayed.

public
JTree(Hashtable<?, ?>
a Hashtable
value
)

Returns a JTree created from a Hashtable which does not display with root.

public
JTree(TreeNode
a TreeNode object
root
)

Returns a JTree with the specified TreeNode as its root, which displays the root node.

public
JTree(TreeNode
a TreeNode object
root
,
boolean
if false, any node without children is a leaf node; if true, only nodes that do not allow children are leaf nodes
asksAllowsChildren
)

Returns a JTree with the specified TreeNode as its root, which displays the root node and which decides whether a node is a leaf node in the specified manner.

public
JTree(TreeModel
the TreeModel to use as the data model
newModel
)

Returns an instance of JTree which displays the root node -- the tree is created using the specified data model.

Method Summary

Modifier and TypeMethod and Description
public void
addSelectionInterval(int
the first index in the range to add to the selection
index0
,
int
the last index in the range to add to the selection
index1
)

Adds the specified rows (inclusive) to the selection.

public void
addSelectionPath(TreePath
the TreePath to add
path
)

Adds the node identified by the specified TreePath to the current selection.

public void
addSelectionPaths(TreePath[]
an array of TreePath objects that specifies the nodes to add
paths
)

Adds each path in the array of paths to the current selection.

public void
addSelectionRow(int
an integer specifying the row of the node to add, where 0 is the first row in the display
row
)

Adds the path at the specified row to the current selection.

public void
addSelectionRows(int[]
an array of ints specifying the rows to add, where 0 indicates the first row in the display
rows
)

Adds the paths at each of the specified rows to the current selection.

public void
addTreeExpansionListener(TreeExpansionListener
a TreeExpansionListener that will be notified when a tree node is expanded or collapsed (a "negative expansion")
tel
)

Adds a listener for TreeExpansion events.

public void
addTreeSelectionListener(TreeSelectionListener
the TreeSelectionListener that will be notified when a node is selected or deselected (a "negative selection")
tsl
)

Adds a listener for TreeSelection events.

public void
addTreeWillExpandListener(TreeWillExpandListener
a TreeWillExpandListener that will be notified when a tree node will be expanded or collapsed (a "negative expansion")
tel
)

Adds a listener for TreeWillExpand events.

private void
public void
cancelEditing()

Cancels the current editing session.

private static void
checkDragEnabled(boolean b)

private static void
public void
clearSelection()

Clears the selection.

protected void
clearToggledPaths()

Clears the cache of toggled tree paths.

public void
collapsePath(TreePath
the TreePath identifying a node
path
)

Ensures that the node identified by the specified path is collapsed and viewable.

public void
collapseRow(int
an integer specifying a display row, where 0 is the first row in the display
row
)

Ensures that the node in the specified row is collapsed.

public String

Returns:

the String representation of the node's value
convertValueToText
(Object
the Object to convert to text
value
,
boolean
true if the node is selected
selected
,
boolean
true if the node is expanded
expanded
,
boolean
true if the node is a leaf node
leaf
,
int
an integer specifying the node's display row, where 0 is the first row in the display
row
,
boolean
true if the node has the focus
hasFocus
)

Called by the renderers to convert the specified value to text.

protected static TreeModel

Returns:

a TreeModel wrapping the specified object
createTreeModel
(Object
the Object used as the foundation for the TreeModel
value
)

Returns a TreeModel wrapping the specified object.

protected TreeModelListener

Returns:

the instance of TreeModelHandler
createTreeModelListener
()

Creates and returns an instance of TreeModelHandler.

pack-priv void
dndDone()

Overrides javax.swing.JComponent.dndDone.

Called to indicate to this component that DnD is done.
pack-priv JTree.DropLocation

Returns:

the drop location, or null
dropLocationForPoint
(Point
the point to calculate a drop location for
p
)

Overrides javax.swing.JComponent.dropLocationForPoint.

Calculates a drop location in this component, representing where a drop at the given point should insert data.
public void
expandPath(TreePath
the TreePath identifying a node
path
)

Ensures that the node identified by the specified path is expanded and viewable.

private void
expandRoot()

Expands the root path, assuming the current TreeModel has been set.

public void
expandRow(int
an integer specifying a display row, where 0 is the first row in the display
row
)

Ensures that the node in the specified row is expanded and viewable.

public void
fireTreeCollapsed(TreePath
the TreePath indicating the node that was collapsed
path
)

Notifies all listeners that have registered interest for notification on this event type.

public void
fireTreeExpanded(TreePath
the TreePath indicating the node that was expanded
path
)

Notifies all listeners that have registered interest for notification on this event type.

public void
fireTreeWillCollapse(TreePath
the TreePath indicating the node that was expanded
path
)

Notifies all listeners that have registered interest for notification on this event type.

public void
fireTreeWillExpand(TreePath
the TreePath indicating the node that was expanded
path
)

Notifies all listeners that have registered interest for notification on this event type.

protected void
fireValueChanged(TreeSelectionEvent
the TreeSelectionEvent to be fired; generated by the TreeSelectionModel when a node is selected or deselected
e
)

Notifies all listeners that have registered interest for notification on this event type.

public AccessibleContext

Returns:

an AccessibleJTree that serves as the AccessibleContext of this JTree
getAccessibleContext
()

Overrides java.awt.Component.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this JTree.
public TreePath

Returns:

path identified as the anchor
getAnchorSelectionPath
()

Returns the path identified as the anchor.

private Object
getArchivableExpandedState()

Returns an object that can be archived indicating what nodes are expanded and what aren't.

public TreeCellEditor

Returns:

the TreeCellEditor in use, or null if the tree cannot be edited
getCellEditor
()

Returns the editor used to edit entries in the tree.

public TreeCellRenderer

Returns:

the TreeCellRenderer that is rendering each cell
getCellRenderer
()

Returns the current TreeCellRenderer that is rendering each cell.

public TreePath

Returns:

the TreePath for the node closest to that location, null if nothing is viewable or there is no model
getClosestPathForLocation
(int
an integer giving the number of pixels horizontally from the left edge of the display area, minus any left margin
x
,
int
an integer giving the number of pixels vertically from the top of the display area, minus any top margin
y
)

Returns the path to the node that is closest to x,y.

public int

Returns:

the row closest to the location, -1 if nothing is viewable or there is no model
getClosestRowForLocation
(int
an integer giving the number of pixels horizontally from the left edge of the display area, minus any left margin
x
,
int
an integer giving the number of pixels vertically from the top of the display area, minus any top margin
y
)

Returns the row to the node that is closest to x,y.

protected static TreeModel

Returns:

the default TreeModel
getDefaultTreeModel
()

Creates and returns a sample TreeModel.

private TreePath[]
getDescendantSelectedPaths(TreePath path, boolean includePath)

Returns an array of paths in the selection that are descendants of path.

protected Enumeration<TreePath>

Returns:

the Enumeration of TreePaths
getDescendantToggledPaths
(TreePath
a path
parent
)

Returns an Enumeration of TreePaths that have been expanded that are descendants of parent.

public boolean

Returns:

the value of the dragEnabled property
getDragEnabled
()

Returns whether or not automatic drag handling is enabled.

public final JTree.DropLocation

Returns:

the drop location
getDropLocation
()

Returns the location that this component should visually indicate as the drop location during a DnD operation over the component, or null if no location is to currently be shown.

public final DropMode

Returns:

the drop mode for this component
getDropMode
()

Returns the drop mode for this component.

public TreePath

Returns:

the TreePath for the node being edited
getEditingPath
()

Returns the path to the element that is currently being edited.

public Enumeration<TreePath>

Returns:

an Enumeration of the descendents of parent, or null if parent is not currently expanded
getExpandedDescendants
(TreePath
the path which is to be examined
parent
)

Returns an Enumeration of the descendants of the path parent that are currently expanded.

public boolean

Returns:

true if selection changes result in the parent path being expanded
getExpandsSelectedPaths
()

Returns the expandsSelectedPaths property.

public boolean

Returns:

the indicator that tells what happens when editing is interrupted
getInvokesStopCellEditing
()

Returns the indicator that tells what happens when editing is interrupted.

public Object

Returns:

the last path component of the selected path, or null if nothing is selected
getLastSelectedPathComponent
()

Returns the last path component of the selected path.

public TreePath

Returns:

path identified as the lead
getLeadSelectionPath
()

Returns the path identified as the lead.

public int

Returns:

an integer giving the row index of the lead path, where 0 is the first row in the display; or -1 if leadPath is null
getLeadSelectionRow
()

Returns the row index corresponding to the lead path.

public int

Returns:

the largest selected row
getMaxSelectionRow
()

Returns the largest selected row.

public int

Returns:

the smallest selected row
getMinSelectionRow
()

Returns the smallest selected row.

public TreeModel

Returns:

the TreeModel that is providing the data
getModel
()

Returns the TreeModel that is providing the data.

private int[]
getModelIndexsForPath(TreePath path)

Returns an array of integers specifying the indices of the components in the path.

public TreePath

Returns:

the TreePath of the next tree element that starts with the prefix; otherwise null
getNextMatch
(String
the string to test for a match
prefix
,
int
the row for starting the search
startingRow
,
Position.Bias
the search direction, either Position.Bias.Forward or Position.Bias.Backward.
bias
)

Returns the TreePath to the next tree element that begins with a prefix.

protected TreePath[]

Returns:

the paths (inclusive) between the specified row indices
getPathBetweenRows
(int
the first index in the range
index0
,
int
the last index in the range
index1
)

Returns the paths (inclusive) between the specified rows.

public Rectangle

Returns:

the Rectangle the node is drawn in, or null
getPathBounds
(TreePath
the TreePath identifying the node
path
)

Returns the Rectangle that the specified node will be drawn into.

private TreePath
getPathForIndexs(int[] indices)

Returns a TreePath created by obtaining the children for each of the indices in indices.

public TreePath

Returns:

the TreePath for the node at that location
getPathForLocation
(int
an integer giving the number of pixels horizontally from the left edge of the display area, minus any left margin
x
,
int
an integer giving the number of pixels vertically from the top of the display area, minus any top margin
y
)

Returns the path for the node at the specified location.

public TreePath

Returns:

the TreePath to the specified node, null if row < 0 or row >= getRowCount()
getPathForRow
(int
an integer specifying a row
row
)

Returns the path for the specified row.

public Dimension

Returns:

a Dimension object containing the preferred size
getPreferredScrollableViewportSize
()

Implements javax.swing.Scrollable.getPreferredScrollableViewportSize.

Returns the preferred display size of a JTree.
public Rectangle

Returns:

the Rectangle the node is drawn in
getRowBounds
(int
the row to be drawn, where 0 is the first row in the display
row
)

Returns the Rectangle that the node at the specified row is drawn in.

public int

Returns:

the number of viewable nodes
getRowCount
()

Returns the number of viewable nodes.

public int

Returns:

the row corresponding to the location, or -1 if the location is not within the bounds of a displayed cell
getRowForLocation
(int
an integer giving the number of pixels horizontally from the left edge of the display area, minus any left margin
x
,
int
an integer giving the number of pixels vertically from the top of the display area, minus any top margin
y
)

Returns the row for the specified location.

public int

Returns:

an integer specifying the display row, where 0 is the first row in the display, or -1 if any of the elements in path are hidden under a collapsed parent.
getRowForPath
(TreePath
the TreePath identifying a node
path
)

Returns the row that displays the node identified by the specified path.

public int

Returns:

the height of each row
getRowHeight
()

Returns the height of each row.

public int

Returns:

the "block" increment for scrolling in the specified direction
getScrollableBlockIncrement
(Rectangle
the view area visible within the viewport
visibleRect
,
int
either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL
orientation
,
int
less than zero to scroll up/left, greater than zero for down/right.
direction
)

Implements javax.swing.Scrollable.getScrollableBlockIncrement.

Returns the amount for a block increment, which is the height or width of visibleRect, based on orientation.
public boolean

Returns:

whether the tree should track the height of the viewport
getScrollableTracksViewportHeight
()

Implements javax.swing.Scrollable.getScrollableTracksViewportHeight.

Returns false to indicate that the height of the viewport does not determine the height of the table, unless the preferred height of the tree is smaller than the viewports height.
public boolean

Returns:

whether the tree should track the width of the viewport
getScrollableTracksViewportWidth
()

Implements javax.swing.Scrollable.getScrollableTracksViewportWidth.

Returns false to indicate that the width of the viewport does not determine the width of the table, unless the preferred width of the tree is smaller than the viewports width.
public int

Returns:

the "unit" increment for scrolling in the specified direction
getScrollableUnitIncrement
(Rectangle
the view area visible within the viewport
visibleRect
,
int
either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL
orientation
,
int
less than zero to scroll up/left, greater than zero for down/right
direction
)

Implements javax.swing.Scrollable.getScrollableUnitIncrement.

Returns the amount to increment when scrolling.
public boolean

Returns:

the value of the scrollsOnExpand property
getScrollsOnExpand
()

Returns the value of the scrollsOnExpand property.

public int

Returns:

the number of nodes selected
getSelectionCount
()

Returns the number of nodes selected.

public TreeSelectionModel

Returns:

the model for selections
getSelectionModel
()

Returns the model for selections.

public TreePath

Returns:

the TreePath for the first selected node, or null if nothing is currently selected
getSelectionPath
()

Returns the path to the first selected node.

public TreePath[]

Returns:

an array of TreePath objects indicating the selected nodes, or null if nothing is currently selected
getSelectionPaths
()

Returns the paths of all selected values.

public int[]

Returns:

an array of integers that identifies all currently selected rows where 0 is the first row in the display
getSelectionRows
()

Returns all of the currently selected rows.

public boolean

Returns:

the value of the showsRootHandles property
getShowsRootHandles
()

Returns the value of the showsRootHandles property.

public int

Returns:

number of mouse clicks before node is expanded
getToggleClickCount
()

Returns the number of mouse clicks needed to expand or close a node.

public String

Returns:

a string containing the tooltip or null if event is null
getToolTipText
(MouseEvent
the MouseEvent that initiated the ToolTip display
event
)

Overrides javax.swing.JComponent.getToolTipText.

Overrides JComponent's getToolTipText method in order to allow renderer's tips to be used if it has text set.
public TreeExpansionListener[]

Returns:

all of the TreeExpansionListeners added or an empty array if no listeners have been added
getTreeExpansionListeners
()

Returns an array of all the TreeExpansionListeners added to this JTree with addTreeExpansionListener().

public TreeSelectionListener[]

Returns:

all of the TreeSelectionListeners added or an empty array if no listeners have been added
getTreeSelectionListeners
()

Returns an array of all the TreeSelectionListeners added to this JTree with addTreeSelectionListener().

public TreeWillExpandListener[]

Returns:

all of the TreeWillExpandListeners added or an empty array if no listeners have been added
getTreeWillExpandListeners
()

Returns an array of all the TreeWillExpandListeners added to this JTree with addTreeWillExpandListener().

public TreeUI

Returns:

the TreeUI object that renders this component
getUI
()

Overrides javax.swing.JComponent.getUI.

Returns the L&F object that renders this component.
public String

Returns:

the string "TreeUI"
getUIClassID
()

Overrides javax.swing.JComponent.getUIClassID.

Returns the name of the L&F class that renders this component.
public int

Returns:

the number of rows displayed
getVisibleRowCount
()

Returns the number of rows that are displayed in the display area.

public boolean

Returns:

true if the path has ever been expanded
hasBeenExpanded
(TreePath
a TreePath identifying a node
path
)

Returns true if the node identified by the path has ever been expanded.

public boolean

Returns:

true if any of the nodes in the node's path are collapsed, false if all nodes in the path are expanded
isCollapsed
(TreePath
the TreePath to check
path
)

Returns true if the value identified by path is currently collapsed, this will return false if any of the values in path are currently not being displayed.

public boolean

Returns:

true if the node is currently collapsed, otherwise false
isCollapsed
(int
the row to check, where 0 is the first row in the display
row
)

Returns true if the node at the specified display row is collapsed.

public boolean

Returns:

true if the tree is editable
isEditable
()

Returns true if the tree is editable.

public boolean

Returns:

true if the user is currently editing a node
isEditing
()

Returns true if the tree is being edited.

public boolean

Returns:

false if any of the nodes in the node's path are collapsed, true if all nodes in the path are expanded
isExpanded
(TreePath
the TreePath specifying the node to check
path
)

Returns true if the node identified by the path is currently expanded,

public boolean

Returns:

true if the node is currently expanded, otherwise false
isExpanded
(int
the row to check, where 0 is the first row in the display
row
)

Returns true if the node at the specified display row is currently expanded.

public boolean

Returns:

true if the height of each row is a fixed size
isFixedRowHeight
()

Returns true if the height of each display row is a fixed size.

public boolean

Returns:

true if a large model is suggested
isLargeModel
()

Returns true if the tree is configured for a large model.

public boolean

Returns:

true if every parent node and the node itself is editable
isPathEditable
(TreePath
a TreePath identifying a node
path
)

Returns isEditable.

public boolean

Returns:

true if the node is selected
isPathSelected
(TreePath
a TreePath identifying a node
path
)

Returns true if the item identified by the path is currently selected.

public boolean

Returns:

true if the root node of the tree is displayed
isRootVisible
()

Returns true if the root node of the tree is displayed.

public boolean

Returns:

true if the node is selected
isRowSelected
(int
an integer specifying a display row, where 0 is the first row in the display
row
)

Returns true if the node identified by row is selected.

public boolean

Returns:

true if the selection is currently empty
isSelectionEmpty
()

Returns true if the selection is currently empty.

public boolean

Returns:

true if the node is viewable, otherwise false
isVisible
(TreePath
TreePath identifying a node
path
)

Returns true if the value identified by path is currently viewable, which means it is either the root or all of its parents are expanded.

public void
makeVisible(TreePath
the TreePath to make visible
path
)

Ensures that the node identified by path is currently viewable.

protected String

Returns:

a string representation of this JTree.
paramString
()

Overrides javax.swing.JComponent.paramString.

Returns a string representation of this JTree.
private void
readObject(ObjectInputStream
the ObjectInputStream from which to read
s
)

Hides javax.swing.JComponent.readObject.

We use the ObjectInputStream "registerValidation" callback to update the UI for the entire tree of components after they've all been read in.
protected boolean

Returns:

true if a descendant was selected
removeDescendantSelectedPaths
(TreePath
a path
path
,
boolean
is true and path is selected, it will be removed from the selection.
includePath
)

Removes any paths in the selection that are descendants of path.

pack-priv void
removeDescendantSelectedPaths(TreeModelEvent e)

Removes any paths from the selection model that are descendants of the nodes identified by in e.

protected void
removeDescendantToggledPaths(Enumeration<TreePath>
an enumeration of the paths to remove; a value of null is ignored
toRemove
)

Removes any descendants of the TreePaths in toRemove that have been expanded.

public void
removeSelectionInterval(int
the first row to remove from the selection
index0
,
int
the last row to remove from the selection
index1
)

Removes the specified rows (inclusive) from the selection.

public void
removeSelectionPath(TreePath
the TreePath identifying a node
path
)

Removes the node identified by the specified path from the current selection.

public void
removeSelectionPaths(TreePath[]
an array of TreePath objects that specifies the nodes to remove
paths
)

Removes the nodes identified by the specified paths from the current selection.

public void
removeSelectionRow(int
the row to remove
row
)

Removes the row at the index row from the current selection.

public void
removeSelectionRows(int[]
an array of ints specifying display rows, where 0 is the first row in the display
rows
)

Removes the rows that are selected at each of the specified rows.

public void
removeTreeExpansionListener(TreeExpansionListener
the TreeExpansionListener to remove
tel
)

Removes a listener for TreeExpansion events.

public void
removeTreeSelectionListener(TreeSelectionListener
the TreeSelectionListener to remove
tsl
)

Removes a TreeSelection listener.

public void
removeTreeWillExpandListener(TreeWillExpandListener
the TreeWillExpandListener to remove
tel
)

Removes a listener for TreeWillExpand events.

public void
scrollPathToVisible(TreePath
the TreePath identifying the node to bring into view
path
)

Makes sure all the path components in path are expanded (except for the last path component) and scrolls so that the node identified by the path is displayed.

public void
scrollRowToVisible(int
an integer specifying the row to scroll, where 0 is the first row in the display
row
)

Scrolls the item identified by row until it is displayed.

public void
setAnchorSelectionPath(TreePath
the new anchor path
newPath
)

Sets the path identified as the anchor.

public void
setCellEditor(TreeCellEditor
the TreeCellEditor to use
cellEditor
)

Sets the cell editor.

public void
setCellRenderer(TreeCellRenderer
the TreeCellRenderer that is to render each cell
x
)

Sets the TreeCellRenderer that will be used to draw each cell.

public void
setDragEnabled(boolean
whether or not to enable automatic drag handling
b
)

Turns on or off automatic drag handling.

pack-priv Object

Returns:

any saved state for this component, or null if none
setDropLocation
(TransferHandler.DropLocation
the drop location (as calculated by dropLocationForPoint) or null if there's no longer a valid drop location
location
,
Object
the state object saved earlier for this component, or null
state
,
boolean
whether or not the method is being called because an actual drop occurred
forDrop
)

Overrides javax.swing.JComponent.setDropLocation.

Called to set or clear the drop location during a DnD operation.
public final void
setDropMode(DropMode
the drop mode to use
dropMode
)

Sets the drop mode for this component.

public void
setEditable(boolean
a boolean value, true if the tree is editable
flag
)

Determines whether the tree is editable.

protected void
setExpandedState(TreePath
a TreePath identifying a node
path
,
boolean
if true, all parents of path and path are marked as expanded. Otherwise, all parents of path are marked EXPANDED, but path itself is marked collapsed.
state
)

Sets the expanded state of this JTree.

public void
setExpandsSelectedPaths(boolean
the new value for expandsSelectedPaths
newValue
)

Configures the expandsSelectedPaths property.

public void
setInvokesStopCellEditing(boolean
true means that stopCellEditing is invoked when editing is interrupted, and data is saved; false means that cancelCellEditing is invoked, and changes are lost
newValue
)

Determines what happens when editing is interrupted by selecting another node in the tree, a change in the tree's data, or by some other means.

public void
setLargeModel(boolean
true to suggest a large model to the UI
newValue
)

Specifies whether the UI should use a large model.

public void
setLeadSelectionPath(TreePath
the new lead path
newPath
)

Sets the path identifies as the lead.

public void
setModel(TreeModel
the TreeModel that is to provide the data
newModel
)

Sets the TreeModel that will provide the data.

public void
setRootVisible(boolean
true if the root node of the tree is to be displayed
rootVisible
)

Determines whether or not the root node from the TreeModel is visible.

public void
setRowHeight(int
the height of each cell, in pixels
rowHeight
)

Sets the height of each cell, in pixels.

public void
setScrollsOnExpand(boolean
false to disable scrolling on expansion; true to enable it
newValue
)

Sets the scrollsOnExpand property, which determines whether the tree might scroll to show previously hidden children.

public void
setSelectionInterval(int
the first index in the range to select
index0
,
int
the last index in the range to select
index1
)

Selects the rows in the specified interval (inclusive).

public void
setSelectionModel(TreeSelectionModel
the TreeSelectionModel to use, or null to disable selections
selectionModel
)

Sets the tree's selection model.

public void
setSelectionPath(TreePath
the TreePath specifying the node to select
path
)

Selects the node identified by the specified path.

public void
setSelectionPaths(TreePath[]
an array of TreePath objects that specifies the nodes to select
paths
)

Selects the nodes identified by the specified array of paths.

public void
setSelectionRow(int
the row to select, where 0 is the first row in the display
row
)

Selects the node at the specified row in the display.

public void
setSelectionRows(int[]
an array of ints specifying the rows to select, where 0 indicates the first row in the display
rows
)

Selects the nodes corresponding to each of the specified rows in the display.

public void
setShowsRootHandles(boolean
true if root handles should be displayed; otherwise, false
newValue
)

Sets the value of the showsRootHandles property, which specifies whether the node handles should be displayed.

public void
setToggleClickCount(int
the number of mouse clicks to get a node expanded or closed
clickCount
)

Sets the number of mouse clicks before a node will expand or close.

public void
setUI(TreeUI
the TreeUI L&F object
ui
)

Sets the L&F object that renders this component.

pack-priv void
public void
setVisibleRowCount(int
the number of rows to display
newCount
)

Sets the number of rows that are to be displayed.

private void
public void
startEditingAtPath(TreePath
the TreePath identifying a node
path
)

Selects the node identified by the specified path and initiates editing.

public boolean

Returns:

true if editing was in progress and is now stopped, false if editing was not in progress
stopEditing
()

Ends the current editing session.

public void
treeDidChange()

Sent when the tree has changed enough that we need to resize the bounds, but not enough that we need to remove the expanded node set (e.g nodes were expanded or collapsed, or nodes were inserted into the tree).

private void
unarchiveExpandedState(Object state)

Updates the expanded state of nodes in the tree based on the previously archived state state.

public void
updateUI()

Overrides javax.swing.JComponent.updateUI.

Notification from the UIManager that the L&F has changed.
private void
writeObject(ObjectOutputStream
the ObjectOutputStream in which to write
s
)

Hides javax.swing.JComponent.writeObject.

Before writing a JComponent to an ObjectOutputStream we temporarily uninstall its UI.
Inherited from javax.swing.JComponent:
_paintImmediatelyaddAncestorListeneraddNotifyaddVetoableChangeListeneralwaysOnTopcheckIfChildObscuredBySiblingclientPropertyChangedcomponentInputMapChangedcomputeVisibleRectcomputeVisibleRectcompWriteObjectNotifycontainscreateToolTipdisableenablefirePropertyChangefirePropertyChangefirePropertyChangefireVetoableChangegetActionForKeyStrokegetActionMapgetActionMapgetAlignmentXgetAlignmentYgetAncestorListenersgetAutoscrollsgetBaselinegetBaselineResizeBehaviorgetBordergetBoundsgetClientPropertygetComponentGraphicsgetComponentPopupMenugetConditionForKeyStrokegetCreatedDoubleBuffergetDebugGraphicsOptionsgetDefaultLocalegetFontMetricsgetGraphicsgetGraphicsInvokedgetHeightgetInheritsPopupMenugetInputMapgetInputMapgetInputMapgetInputVerifiergetInsetsgetInsetsgetListenersgetLocationgetManagingFocusBackwardTraversalKeysgetManagingFocusForwardTraversalKeysgetMaximumSizegetMinimumSizegetNextFocusableComponentgetPopupLocationgetPreferredSizegetRegisteredKeyStrokesgetRootPanegetSizegetToolTipLocationgetToolTipTextgetTopLevelAncestorgetTransferHandlergetVerifyInputWhenFocusTargetgetVetoableChangeListenersgetVisibleRectgetWidthgetWriteObjCountergetXgetYgrabFocushideisDoubleBufferedisLightweightComponentisManagingFocusisOpaqueisOptimizedDrawingEnabledisPaintingisPaintingForPrintisPaintingOriginisPaintingTileisRequestFocusEnabledisValidateRootpaintpaintBorderpaintChildrenpaintComponentpaintForceDoubleBufferedpaintImmediatelypaintImmediatelypaintToOffscreenprintprintAllprintBorderprintChildrenprintComponentprocessComponentKeyEventprocessKeyBindingprocessKeyBindingsprocessKeyBindingsForAllComponentsprocessKeyEventprocessMouseEventprocessMouseMotionEventputClientPropertyrectangleIsObscuredregisterKeyboardActionregisterKeyboardActionremoveAncestorListenerremoveNotifyremoveVetoableChangeListenerrepaintrepaintrequestDefaultFocusrequestFocusrequestFocusrequestFocusInWindowrequestFocusInWindowresetKeyboardActionsreshaperevalidatesafelyGetGraphicssafelyGetGraphicsscrollRectToVisiblesetActionMapsetAlignmentXsetAlignmentYsetAutoscrollssetBackgroundsetBordersetComponentPopupMenusetCreatedDoubleBuffersetDebugGraphicsOptionssetDefaultLocalesetDoubleBufferedsetEnabledsetFocusTraversalKeyssetFontsetForegroundsetInheritsPopupMenusetInputMapsetInputVerifiersetMaximumSizesetMinimumSizesetNextFocusableComponentsetOpaquesetPaintingChildsetPreferredSizesetRequestFocusEnabledsetToolTipTextsetTransferHandlersetUIsetVerifyInputWhenFocusTargetsetVisiblesetWriteObjCountershouldDebugGraphicssuperProcessMouseMotionEventunregisterKeyboardActionupdate