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)
boolean
getScrollableTracksViewportHeight()
boolean
getScrollableTracksViewportWidth()
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, getMousePosition, 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, getMousePosition, 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, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

ANCHOR_SELECTION_PATH_PROPERTY

public static final String ANCHOR_SELECTION_PATH_PROPERTY
Field Value:
"anchorSelectionPath"
Since:
1.3

CELL_EDITOR_PROPERTY

public static final String CELL_EDITOR_PROPERTY
Field Value:
"cellEditor"

CELL_RENDERER_PROPERTY

public static final String CELL_RENDERER_PROPERTY
Field Value:
"cellRenderer"

EDITABLE_PROPERTY

public static final String EDITABLE_PROPERTY
Field Value:
"editable"

EXPANDS_SELECTED_PATHS_PROPERTY

public static final String EXPANDS_SELECTED_PATHS_PROPERTY
Field Value:
"expandsSelectedPaths"
Since:
1.3

INVOKES_STOP_CELL_EDITING_PROPERTY

public static final String INVOKES_STOP_CELL_EDITING_PROPERTY
Field Value:
"invokesStopCellEditing"

LARGE_MODEL_PROPERTY

public static final String LARGE_MODEL_PROPERTY
Field Value:
"largeModel"

LEAD_SELECTION_PATH_PROPERTY

public static final String LEAD_SELECTION_PATH_PROPERTY
Field Value:
"leadSelectionPath"
Since:
1.3

ROOT_VISIBLE_PROPERTY

public static final String ROOT_VISIBLE_PROPERTY
Field Value:
"rootVisible"

ROW_HEIGHT_PROPERTY

public static final String ROW_HEIGHT_PROPERTY
Field Value:
"rowHeight"

SCROLLS_ON_EXPAND_PROPERTY

public static final String SCROLLS_ON_EXPAND_PROPERTY
Field Value:
"scrollsOnExpand"

SELECTION_MODEL_PROPERTY

public static final String SELECTION_MODEL_PROPERTY
Field Value:
"selectionModel"

SHOWS_ROOT_HANDLES_PROPERTY

public static final String SHOWS_ROOT_HANDLES_PROPERTY
Field Value:
"showsRootHandles"

TOGGLE_CLICK_COUNT_PROPERTY

public static final String TOGGLE_CLICK_COUNT_PROPERTY
Field Value:
"toggleClickCount"

TREE_MODEL_PROPERTY

public static final String TREE_MODEL_PROPERTY
Field Value:
"model"

VISIBLE_ROW_COUNT_PROPERTY

public static final String VISIBLE_ROW_COUNT_PROPERTY
Field Value:
"visibleRowCount"

cellEditor

protected TreeCellEditor cellEditor

cellRenderer

protected TreeCellRenderer cellRenderer

editable

protected boolean editable

invokesStopCellEditing

protected boolean invokesStopCellEditing

largeModel

protected boolean largeModel

rootVisible

protected boolean rootVisible

rowHeight

protected int rowHeight

scrollsOnExpand

protected boolean scrollsOnExpand

selectionModel

protected TreeSelectionModel selectionModel

selectionRedirector

protected JTree.TreeSelectionRedirector selectionRedirector
Redirects TreeSelectionEvents so that the source is this JTree.

showsRootHandles

protected boolean showsRootHandles

toggleClickCount

protected int toggleClickCount

treeModel

protected TreeModel treeModel

treeModelListener

protected TreeModelListener treeModelListener
Handles TreeModelEvents to update the expandedState.

visibleRowCount

protected int visibleRowCount

Constructor Details

JTree

public JTree()
Creates a new JTree object.

JTree

public JTree(Hashtable value)
Creates a new JTree object.
Parameters:
value - the initial nodes in the tree

JTree

public JTree(Vector value)
Creates a new JTree object.
Parameters:
value - the initial nodes in the tree

JTree

public JTree(Object[] value)
Creates a new JTree object.
Parameters:
value - the initial nodes in the tree

JTree

public JTree(TreeModel model)
Creates a new JTree object.
Parameters:
model - the model to use

JTree

public JTree(TreeNode root)
Creates a new JTree object.
Parameters:
root - the root node

JTree

public JTree(TreeNode root,
             boolean asksAllowChildren)
Creates a new JTree object.
Parameters:
root - the root node
asksAllowChildren - if false, all nodes without children are leaf nodes. If true, only nodes that do not allow children are leaf nodes.

Method Details

addSelectionInterval

public void addSelectionInterval(int index0,
                                 int index1)
Select all rows between the two given indexes, inclusive. The method will not select the inner leaves and braches of the currently collapsed nodes in this interval.
Parameters:
index0 - the starting row, inclusive
index1 - the ending row, inclusive

addSelectionPath

public void addSelectionPath(TreePath path)

addSelectionPaths

public void addSelectionPaths(TreePath[] paths)

addSelectionRow

public void addSelectionRow(int row)

addSelectionRows

public void addSelectionRows(int[] rows)

addTreeExpansionListener

public void addTreeExpansionListener(TreeExpansionListener listener)
Adds a TreeExpansionListener object to the tree.
Parameters:
listener - the listener to add

addTreeSelectionListener

public void addTreeSelectionListener(TreeSelectionListener listener)
Adds a TreeSelctionListener object to the tree.
Parameters:
listener - the listener to add

addTreeWillExpandListener

public void addTreeWillExpandListener(TreeWillExpandListener listener)
Adds a TreeWillExpandListener object to the tree.
Parameters:
listener - the listener to add

cancelEditing

public void cancelEditing()

clearSelection

public void clearSelection()

clearToggledPaths

protected void clearToggledPaths()

collapsePath

public void collapsePath(TreePath path)

collapseRow

public void collapseRow(int row)

convertValueToText

public String convertValueToText(Object value,
                                 boolean selected,
                                 boolean expanded,
                                 boolean leaf,
                                 int row,
                                 boolean hasFocus)
Converts the specified value to a String. This is used by the renderers of this JTree and its nodes. This implementation simply returns value.toString() and ignores all other parameters. Subclass this method to control the conversion.
Parameters:
value - the value that is converted to a String
selected - indicates if that value is selected or not
expanded - indicates if that value is expanded or not
leaf - indicates if that value is a leaf node or not
row - the row of the node
hasFocus - indicates if that node has focus or not

createTreeModel

protected static TreeModel createTreeModel(Object value)
Creates a new TreeModel object.
Parameters:
value - the values stored in the model

createTreeModelListener

protected TreeModelListener createTreeModelListener()
Creates and returns an instance of JTree.TreeModelHandler.
Returns:
an instance of JTree.TreeModelHandler

expandPath

public void expandPath(TreePath path)

expandRow

public void expandRow(int row)

fireTreeCollapsed

public void fireTreeCollapsed(TreePath path)
Notifies all listeners that the tree was collapsed.
Parameters:
path - the path to the node that was collapsed

fireTreeExpanded

public void fireTreeExpanded(TreePath path)
Notifies all listeners that the tree was expanded.
Parameters:
path - the path to the node that was expanded

fireTreeWillCollapse

public void fireTreeWillCollapse(TreePath path)
            throws ExpandVetoException
Notifies all listeners that the tree will collapse.
Parameters:
path - the path to the node that will collapse

fireTreeWillExpand

public void fireTreeWillExpand(TreePath path)
            throws ExpandVetoException
Notifies all listeners that the tree will expand.
Parameters:
path - the path to the node that will expand

fireValueChanged

protected void fireValueChanged(TreeSelectionEvent event)
Notifies all listeners when the selection of the tree changed.
Parameters:
event - the event to send

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this JTree.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in interface JComponent
Returns:
the associated context

getAnchorSelectionPath

public TreePath getAnchorSelectionPath()
Since:
1.3

getCellEditor

public TreeCellEditor getCellEditor()

getCellRenderer

public TreeCellRenderer getCellRenderer()

getClosestPathForLocation

public TreePath getClosestPathForLocation(int x,
                                          int y)

getClosestRowForLocation

public int getClosestRowForLocation(int x,
                                    int y)

getDefaultTreeModel

protected static TreeModel getDefaultTreeModel()
Returns a sample TreeModel that can be used in a JTree. This can be used in Bean- or GUI-Builders to show something interesting.
Returns:
a sample TreeModel that can be used in a JTree

getDescendantToggledPaths

protected Enumeration getDescendantToggledPaths(TreePath parent)

getDragEnabled

public boolean getDragEnabled()
Return the value of the dragEnabled property.
Returns:
the value
Since:
1.4

getEditingPath

public TreePath getEditingPath()

getExpandedDescendants

public 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. If the state of any node is beeing toggled while this method is executing this change may be left unaccounted.
Parameters:
path - The parent of this request
Returns:
An Enumeration containing TreePath objects

getExpandsSelectedPaths

public boolean getExpandsSelectedPaths()
Since:
1.3

getInvokesStopCellEditing

public boolean getInvokesStopCellEditing()

getLastSelectedPathComponent

public Object getLastSelectedPathComponent()

getLeadSelectionPath

public TreePath getLeadSelectionPath()

getLeadSelectionRow

public int getLeadSelectionRow()

getMaxSelectionRow

public int getMaxSelectionRow()

getMinSelectionRow

public int getMinSelectionRow()

getModel

public TreeModel getModel()
Returns the model of this JTree object.
Returns:
the associated TreeModel

getNextMatch

public TreePath getNextMatch(String prefix,
                             int startingRow,
                             Position.Bias bias)
Returns the next table element (beginning from the row startingRow that starts with prefix. Searching is done in the direction specified by bias.
Parameters:
prefix - the prefix to search for in the cell values
startingRow - the index of the row where to start searching from
bias - the search direction, either Position.Bias.Forward or Position.Bias.Backward
Returns:
the path to the found element or -1 if no such element has been found
Throws:
IllegalArgumentException - if prefix is null or startingRow is not valid
Since:
1.4

getPathBetweenRows

protected TreePath[] getPathBetweenRows(int index0,
                                        int index1)
Get the pathes that are displayes between the two given rows.
Parameters:
index0 - the starting row, inclusive
index1 - the ending row, inclusive
Returns:
the array of the tree pathes

getPathBounds

public Rectangle getPathBounds(TreePath path)

getPathForLocation

public TreePath getPathForLocation(int x,
                                   int y)

getPathForRow

public TreePath getPathForRow(int row)

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Returns the preferred viewport size.
Specified by:
getPreferredScrollableViewportSize in interface Scrollable
Returns:
the preferred size

getRowBounds

public Rectangle getRowBounds(int row)

getRowCount

public int getRowCount()

getRowForLocation

public int getRowForLocation(int x,
                             int y)

getRowForPath

public int getRowForPath(TreePath path)

getRowHeight

public int getRowHeight()

getScrollableBlockIncrement

public int getScrollableBlockIncrement(Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Specified by:
getScrollableBlockIncrement in interface Scrollable

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Specified by:
getScrollableTracksViewportHeight in interface Scrollable

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Specified by:
getScrollableTracksViewportWidth in interface Scrollable

getScrollableUnitIncrement

public int getScrollableUnitIncrement(Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Return the preferred scrolling amount (in pixels) for the given scrolling direction and orientation. This method handles a partially exposed row by returning the distance required to completely expose the item.
Specified by:
getScrollableUnitIncrement in interface Scrollable
Parameters:
visibleRect - the currently visible part of the component.
orientation - the scrolling orientation
direction - the scrolling direction (negative - up, positive -down). The values greater than one means that more mouse wheel or similar events were generated, and hence it is better to scroll the longer distance.

getScrollsOnExpand

public boolean getScrollsOnExpand()

getSelectionCount

public int getSelectionCount()

getSelectionModel

public TreeSelectionModel getSelectionModel()

getSelectionPath

public TreePath getSelectionPath()

getSelectionPaths

public TreePath[] getSelectionPaths()

getSelectionRows

public int[] getSelectionRows()

getShowsRootHandles

public boolean getShowsRootHandles()

getToggleClickCount

public int getToggleClickCount()
Since:
1.3

getTreeExpansionListeners

public TreeExpansionListener[] getTreeExpansionListeners()
Returns all added TreeExpansionListener objects.
Returns:
an array of listeners

getTreeSelectionListeners

public TreeSelectionListener[] getTreeSelectionListeners()
Returns all added TreeSelectionListener objects.
Returns:
an array of listeners

getTreeWillExpandListeners

public TreeWillExpandListener[] getTreeWillExpandListeners()
Returns all added TreeWillExpandListener objects.
Returns:
an array of listeners

getUI

public TreeUI getUI()
Return the UI associated with this JTree object.
Returns:
the associated TreeUI object

getUIClassID

public String getUIClassID()
This method returns the String ID of the UI class of Separator.
Overrides:
getUIClassID in interface JComponent
Returns:
The UI class' String ID.

getVisibleRowCount

public int getVisibleRowCount()

hasBeenExpanded

public boolean hasBeenExpanded(TreePath path)

isCollapsed

public boolean isCollapsed(int row)

isCollapsed

public boolean isCollapsed(TreePath path)

isEditable

public boolean isEditable()
Checks if this JTree object is editable.
Returns:
true if this tree object is editable, false otherwise

isEditing

public boolean isEditing()

isExpanded

public boolean isExpanded(int row)

isExpanded

public boolean isExpanded(TreePath path)

isFixedRowHeight

public boolean isFixedRowHeight()

isLargeModel

public boolean isLargeModel()

isPathEditable

public boolean isPathEditable(TreePath path)

isPathSelected

public boolean isPathSelected(TreePath path)

isRootVisible

public boolean isRootVisible()
Checks if the root element is visible.
Returns:
true if the root element is visible, false otherwise

isRowSelected

public boolean isRowSelected(int row)
Returns true when the specified row is selected, false otherwise. This call is delegated to the TreeSelectionModel.isRowSelected(int) method.
Parameters:
row - the row to check
Returns:
true when the specified row is selected, false otherwise

isSelectionEmpty

public boolean isSelectionEmpty()

isVisible

public boolean isVisible(TreePath path)

makeVisible

public void makeVisible(TreePath path)

paramString

protected String paramString()
A String representation of this JTree. This is intended to be used for debugging. The returned string may be empty but may not be null.
Overrides:
paramString in interface JComponent
Returns:
a String representation of this JTree

removeDescendantSelectedPaths

protected boolean removeDescendantSelectedPaths(TreePath path,
                                                boolean includeSelected)
Removes any paths in the current set of selected paths that are descendants of path. If includePath is set to true and path itself is selected, then it will be removed too.
Parameters:
path - the path from which selected descendants are to be removed
includeSelected - if true then path itself will also be remove if it's selected
Returns:
true if something has been removed, false otherwise
Since:
1.3

removeDescendantToggledPaths

protected void removeDescendantToggledPaths(Enumeration toRemove)
Removes any descendants of the TreePaths in toRemove that have been expanded.
Parameters:
toRemove - - Enumeration of TreePaths that need to be removed from cache of toggled tree paths.

removeSelectionInterval

public void removeSelectionInterval(int index0,
                                    int index1)

removeSelectionPath

public void removeSelectionPath(TreePath path)

removeSelectionPaths

public void removeSelectionPaths(TreePath[] paths)

removeSelectionRow

public void removeSelectionRow(int row)

removeSelectionRows

public void removeSelectionRows(int[] rows)

removeTreeExpansionListener

public void removeTreeExpansionListener(TreeExpansionListener listener)
Removes a TreeExpansionListener object from the tree.
Parameters:
listener - the listener to remove

removeTreeSelectionListener

public void removeTreeSelectionListener(TreeSelectionListener listener)
Removes a TreeSelectionListener object from the tree.
Parameters:
listener - the listener to remove

removeTreeWillExpandListener

public void removeTreeWillExpandListener(TreeWillExpandListener listener)
Removes a TreeWillExpandListener object from the tree.
Parameters:
listener - the listener to remove

scrollPathToVisible

public void scrollPathToVisible(TreePath path)

scrollRowToVisible

public void scrollRowToVisible(int row)

setAnchorSelectionPath

public void setAnchorSelectionPath(TreePath path)
Since:
1.3

setCellEditor

public void setCellEditor(TreeCellEditor editor)

setCellRenderer

public void setCellRenderer(TreeCellRenderer newRenderer)

setDragEnabled

public void setDragEnabled(boolean enabled)
Set the dragEnabled property.
Parameters:
enabled - new value
Since:
1.4

setEditable

public void setEditable(boolean flag)
Sets the editable property.
Parameters:
flag - true to make this tree object editable, false otherwise

setExpandedState

protected void setExpandedState(TreePath path,
                                boolean state)

setExpandsSelectedPaths

public void setExpandsSelectedPaths(boolean flag)
Since:
1.3

setInvokesStopCellEditing

public void setInvokesStopCellEditing(boolean invoke)

setLargeModel

public void setLargeModel(boolean large)

setLeadSelectionPath

public void setLeadSelectionPath(TreePath path)
Since:
1.3

setModel

public void setModel(TreeModel model)
Sets the model to use in JTree.
Parameters:
model - the TreeModel to use

setRootVisible

public void setRootVisible(boolean flag)

setRowHeight

public void setRowHeight(int height)

setScrollsOnExpand

public void setScrollsOnExpand(boolean scroll)

setSelectionInterval

public void setSelectionInterval(int index0,
                                 int index1)

setSelectionModel

public void setSelectionModel(TreeSelectionModel model)

setSelectionPath

public void setSelectionPath(TreePath path)

setSelectionPaths

public void setSelectionPaths(TreePath[] paths)

setSelectionRow

public void setSelectionRow(int row)

setSelectionRows

public void setSelectionRows(int[] rows)

setShowsRootHandles

public void setShowsRootHandles(boolean flag)

setToggleClickCount

public void setToggleClickCount(int count)
Since:
1.3

setUI

public void setUI(TreeUI ui)
Sets the UI associated with this JTree object.
Parameters:
ui - the TreeUI to associate

setVisibleRowCount

public void setVisibleRowCount(int rows)

startEditingAtPath

public void startEditingAtPath(TreePath path)

stopEditing

public boolean stopEditing()

treeDidChange

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). You should never have to invoke this, the UI will invoke this as it needs to.

If the tree uses DefaultTreeModel, you must call DefaultTreeModel.reload(TreeNode) or DefaultTreeModel.reload() after adding or removing nodes. Following the official Java 1.5 API standard, just calling treeDidChange, repaint() or revalidate() does not update the tree appearance properly.


updateUI

public void updateUI()
This method resets the UI used to the Look and Feel defaults..
Overrides:
updateUI in interface JComponent

JTree.java Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.