javax.swing

Class JTree

Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Scrollable, Serializable

public class JTree
extends JComponent
implements Scrollable, Accessible

See Also:
Serialized Form

Nested Class Summary

protected class
JTree.AccessibleJTree
This class implements accessibility support for the JTree class.
static class
JTree.DynamicUtilTreeNode
protected static class
JTree.EmptySelectionModel
A TreeModel that does not allow anything to be selected.
protected class
JTree.TreeModelHandler
Listens to the model of the JTree and updates the property expandedState if nodes are removed or changed.
protected class
JTree.TreeSelectionRedirector
This redirects TreeSelectionEvents and rewrites the source of it to be this JTree.

Nested classes/interfaces inherited from class javax.swing.JComponent

JComponent.AccessibleJComponent

Nested classes/interfaces inherited from class java.awt.Container

Container.AccessibleAWTContainer

Nested classes/interfaces inherited from class java.awt.Component

Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy

Field Summary

static String
ANCHOR_SELECTION_PATH_PROPERTY
static String
CELL_EDITOR_PROPERTY
static String
CELL_RENDERER_PROPERTY
static String
EDITABLE_PROPERTY
static String
EXPANDS_SELECTED_PATHS_PROPERTY
static String
INVOKES_STOP_CELL_EDITING_PROPERTY
static String
LARGE_MODEL_PROPERTY
static String
LEAD_SELECTION_PATH_PROPERTY
static String
ROOT_VISIBLE_PROPERTY
static String
ROW_HEIGHT_PROPERTY
static String
SCROLLS_ON_EXPAND_PROPERTY
static String
SELECTION_MODEL_PROPERTY
static String
SHOWS_ROOT_HANDLES_PROPERTY
static String
TOGGLE_CLICK_COUNT_PROPERTY
static String
TREE_MODEL_PROPERTY
static String
VISIBLE_ROW_COUNT_PROPERTY
protected TreeCellEditor
cellEditor
protected TreeCellRenderer
cellRenderer
protected boolean
editable
protected boolean
invokesStopCellEditing
protected boolean
largeModel
protected boolean
rootVisible
protected int
rowHeight
protected boolean
scrollsOnExpand
protected TreeSelectionModel
selectionModel
protected JTree.TreeSelectionRedirector
selectionRedirector
Redirects TreeSelectionEvents so that the source is this JTree.
protected boolean
showsRootHandles
protected int
toggleClickCount
protected TreeModel
treeModel
protected TreeModelListener
treeModelListener
Handles TreeModelEvents to update the expandedState.
protected int
visibleRowCount

Fields inherited from class javax.swing.JComponent

TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, accessibleContext, listenerList, ui

Fields inherited from class java.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT

Fields inherited from interface java.awt.image.ImageObserver

ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH

Constructor Summary

JTree()
Creates a new JTree object.
JTree(Hashtable value)
Creates a new JTree object.
JTree(Vector value)
Creates a new JTree object.
JTree(Object[] value)
Creates a new JTree object.
JTree(TreeModel model)
Creates a new JTree object.
JTree(TreeNode root)
Creates a new JTree object.
JTree(TreeNode root, boolean asksAllowChildren)
Creates a new JTree object.

Method Summary

void
addSelectionInterval(int index0, int index1)
Select all rows between the two given indexes, inclusive.
void
addSelectionPath(TreePath path)
void
addSelectionPaths(TreePath[] paths)
void
addSelectionRow(int row)
void
addSelectionRows(int[] rows)
void
addTreeExpansionListener(TreeExpansionListener listener)
Adds a TreeExpansionListener object to the tree.
void
addTreeSelectionListener(TreeSelectionListener listener)
Adds a TreeSelctionListener object to the tree.
void
addTreeWillExpandListener(TreeWillExpandListener listener)
Adds a TreeWillExpandListener object to the tree.
void
cancelEditing()
void
clearSelection()
protected void
clearToggledPaths()
void
collapsePath(TreePath path)
void
collapseRow(int row)
String
convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
Converts the specified value to a String.
protected static TreeModel
createTreeModel(Object value)
Creates a new TreeModel object.
protected TreeModelListener
createTreeModelListener()
Creates and returns an instance of JTree.TreeModelHandler.
void
expandPath(TreePath path)
void
expandRow(int row)
void
fireTreeCollapsed(TreePath path)
Notifies all listeners that the tree was collapsed.
void
fireTreeExpanded(TreePath path)
Notifies all listeners that the tree was expanded.
void
fireTreeWillCollapse(TreePath path)
Notifies all listeners that the tree will collapse.
void
fireTreeWillExpand(TreePath path)
Notifies all listeners that the tree will expand.
protected void
fireValueChanged(TreeSelectionEvent event)
Notifies all listeners when the selection of the tree changed.
AccessibleContext
getAccessibleContext()
Gets the AccessibleContext associated with this JTree.
TreePath
getAnchorSelectionPath()
TreeCellEditor
getCellEditor()
TreeCellRenderer
getCellRenderer()
TreePath
getClosestPathForLocation(int x, int y)
int
getClosestRowForLocation(int x, int y)
protected static TreeModel
getDefaultTreeModel()
Returns a sample TreeModel that can be used in a JTree.
protected Enumeration
getDescendantToggledPaths(TreePath parent)
boolean
getDragEnabled()
Return the value of the dragEnabled property.
TreePath
getEditingPath()
Enumeration
getExpandedDescendants(TreePath path)
Returns all TreePath objects which are a descendants of the given path and are exapanded at the moment of the execution of this method.
boolean
getExpandsSelectedPaths()
boolean
getInvokesStopCellEditing()
Object
getLastSelectedPathComponent()
TreePath
getLeadSelectionPath()
int
getLeadSelectionRow()
int
getMaxSelectionRow()
int
getMinSelectionRow()
TreeModel
getModel()
Returns the model of this JTree object.
TreePath
getNextMatch(String prefix, int startingRow, Position.Bias bias)
Returns the next table element (beginning from the row startingRow that starts with prefix.
protected TreePath[]
getPathBetweenRows(int index0, int index1)
Get the pathes that are displayes between the two given rows.
Rectangle
getPathBounds(TreePath path)
TreePath
getPathForLocation(int x, int y)
TreePath
getPathForRow(int row)
Dimension
getPreferredScrollableViewportSize()
Returns the preferred viewport size.
Rectangle
getRowBounds(int row)
int
getRowCount()
int
getRowForLocation(int x, int y)
int
getRowForPath(TreePath path)
int
getRowHeight()
int
getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
Return the preferred scrolling amount (in pixels) for the given scrolling direction and orientation when scrolling in large amounts (pages).
boolean
getScrollableTracksViewportHeight()
Return true if the height of the scrollable is always equal to the view, where it is displayed, height.In such case, the vertical scrolling should not be performed.
boolean
getScrollableTracksViewportWidth()
Return true if the width of the scrollable is always equal to the view, where it is displayed, width (for instance, the text area with the word wrap).
int
getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
Return the preferred scrolling amount (in pixels) for the given scrolling direction and orientation.
boolean
getScrollsOnExpand()
int
getSelectionCount()
TreeSelectionModel
getSelectionModel()
TreePath
getSelectionPath()
TreePath[]
getSelectionPaths()
int[]
getSelectionRows()
boolean
getShowsRootHandles()
int
getToggleClickCount()
TreeExpansionListener[]
getTreeExpansionListeners()
Returns all added TreeExpansionListener objects.
TreeSelectionListener[]
getTreeSelectionListeners()
Returns all added TreeSelectionListener objects.
TreeWillExpandListener[]
getTreeWillExpandListeners()
Returns all added TreeWillExpandListener objects.
TreeUI
getUI()
Return the UI associated with this JTree object.
String
getUIClassID()
This method returns the String ID of the UI class of Separator.
int
getVisibleRowCount()
boolean
hasBeenExpanded(TreePath path)
boolean
isCollapsed(int row)
boolean
isCollapsed(TreePath path)
boolean
isEditable()
Checks if this JTree object is editable.
boolean
isEditing()
boolean
isExpanded(int row)
boolean
isExpanded(TreePath path)
boolean
isFixedRowHeight()
boolean
isLargeModel()
boolean
isPathEditable(TreePath path)
boolean
isPathSelected(TreePath path)
boolean
isRootVisible()
Checks if the root element is visible.
boolean
isRowSelected(int row)
Returns true when the specified row is selected, false otherwise.
boolean
isSelectionEmpty()
boolean
isVisible(TreePath path)
void
makeVisible(TreePath path)
protected String
paramString()
A String representation of this JTree.
protected boolean
removeDescendantSelectedPaths(TreePath path, boolean includeSelected)
Removes any paths in the current set of selected paths that are descendants of path.
protected void
removeDescendantToggledPaths(Enumeration toRemove)
Removes any descendants of the TreePaths in toRemove that have been expanded.
void
removeSelectionInterval(int index0, int index1)
void
removeSelectionPath(TreePath path)
void
removeSelectionPaths(TreePath[] paths)
void
removeSelectionRow(int row)
void
removeSelectionRows(int[] rows)
void
removeTreeExpansionListener(TreeExpansionListener listener)
Removes a TreeExpansionListener object from the tree.
void
removeTreeSelectionListener(TreeSelectionListener listener)
Removes a TreeSelectionListener object from the tree.
void
removeTreeWillExpandListener(TreeWillExpandListener listener)
Removes a TreeWillExpandListener object from the tree.
void
scrollPathToVisible(TreePath path)
void
scrollRowToVisible(int row)
void
setAnchorSelectionPath(TreePath path)
void
setCellEditor(TreeCellEditor editor)
void
setCellRenderer(TreeCellRenderer newRenderer)
void
setDragEnabled(boolean enabled)
Set the dragEnabled property.
void
setEditable(boolean flag)
Sets the editable property.
protected void
setExpandedState(TreePath path, boolean state)
void
setExpandsSelectedPaths(boolean flag)
void
setInvokesStopCellEditing(boolean invoke)
void
setLargeModel(boolean large)
void
setLeadSelectionPath(TreePath path)
void
setModel(TreeModel model)
Sets the model to use in JTree.
void
setRootVisible(boolean flag)
void
setRowHeight(int height)
void
setScrollsOnExpand(boolean scroll)
void
setSelectionInterval(int index0, int index1)
void
setSelectionModel(TreeSelectionModel model)
void
setSelectionPath(TreePath path)
void
setSelectionPaths(TreePath[] paths)
void
setSelectionRow(int row)
void
setSelectionRows(int[] rows)
void
setShowsRootHandles(boolean flag)
void
setToggleClickCount(int count)
void
setUI(TreeUI ui)
Sets the UI associated with this JTree object.
void
setVisibleRowCount(int rows)
void
startEditingAtPath(TreePath path)
boolean
stopEditing()
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).
void
updateUI()
This method resets the UI used to the Look and Feel defaults..

Methods inherited from class javax.swing.JComponent

addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI

Methods inherited from class java.awt.Container

add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, extends EventListener> T[] getListeners, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponentZOrder, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate, validateTree

Methods inherited from class java.awt.Component

action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds,