javax.swing
Class JTree

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTree
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

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
           
protected  TreeCellEditor cellEditor
           
protected  TreeCellRenderer cellRenderer
           
protected  boolean editable
           
static String EDITABLE_PROPERTY
           
static String EXPANDS_SELECTED_PATHS_PROPERTY
           
static String INVOKES_STOP_CELL_EDITING_PROPERTY
           
protected  boolean invokesStopCellEditing
           
static String LARGE_MODEL_PROPERTY
           
protected  boolean largeModel
           
static String LEAD_SELECTION_PATH_PROPERTY
           
static String ROOT_VISIBLE_PROPERTY
           
protected  boolean rootVisible
           
static String ROW_HEIGHT_PROPERTY
           
protected  int rowHeight
           
static String SCROLLS_ON_EXPAND_PROPERTY
           
protected  boolean scrollsOnExpand
           
static String SELECTION_MODEL_PROPERTY
           
protected  TreeSelectionModel selectionModel
           
protected  JTree.TreeSelectionRedirector selectionRedirector
          Redirects TreeSelectionEvents so that the source is this JTree.
static String SHOWS_ROOT_HANDLES_PROPERTY
           
protected  boolean showsRootHandles
           
static String TOGGLE_CLICK_COUNT_PROPERTY
           
protected  int toggleClickCount
           
static String TREE_MODEL_PROPERTY
           
protected  TreeModel treeModel
           
protected  TreeModelListener treeModelListener
          Handles TreeModelEvents to update the expandedState.
static String VISIBLE_ROW_COUNT_PROPERTY
           
protected  int visibleRowCount
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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(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.
JTree(Vector<?> value)
          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<TreePath> getDescendantToggledPaths(TreePath parent)
           
 boolean getDragEnabled()
          Return the value of the dragEnabled property.
 TreePath getEditingPath()
           
 Enumeration<TreePath> 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<TreePath> 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, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CELL_EDITOR_PROPERTY

public static final String CELL_EDITOR_PROPERTY
See Also:
Constant Field Values

CELL_RENDERER_PROPERTY

public static final String CELL_RENDERER_PROPERTY
See Also:
Constant Field Values

EDITABLE_PROPERTY

public static final String EDITABLE_PROPERTY
See Also:
Constant Field Values

INVOKES_STOP_CELL_EDITING_PROPERTY

public static final String INVOKES_STOP_CELL_EDITING_PROPERTY
See Also:
Constant Field Values

LARGE_MODEL_PROPERTY

public static final String LARGE_MODEL_PROPERTY
See Also:
Constant Field Values

ROOT_VISIBLE_PROPERTY

public static final String ROOT_VISIBLE_PROPERTY
See Also:
Constant Field Values

ROW_HEIGHT_PROPERTY

public static final String ROW_HEIGHT_PROPERTY
See Also:
Constant Field Values

SCROLLS_ON_EXPAND_PROPERTY

public static final String SCROLLS_ON_EXPAND_PROPERTY
See Also:
Constant Field Values

SELECTION_MODEL_PROPERTY

public static final String SELECTION_MODEL_PROPERTY
See Also:
Constant Field Values

SHOWS_ROOT_HANDLES_PROPERTY

public static final String SHOWS_ROOT_HANDLES_PROPERTY
See Also:
Constant Field Values

TOGGLE_CLICK_COUNT_PROPERTY

public static final String TOGGLE_CLICK_COUNT_PROPERTY
See Also:
Constant Field Values

TREE_MODEL_PROPERTY

public static final String TREE_MODEL_PROPERTY
See Also:
Constant Field Values

VISIBLE_ROW_COUNT_PROPERTY

public static final String VISIBLE_ROW_COUNT_PROPERTY
See Also:
Constant Field Values

ANCHOR_SELECTION_PATH_PROPERTY

public static final String ANCHOR_SELECTION_PATH_PROPERTY
Since:
1.3
See Also:
Constant Field Values

LEAD_SELECTION_PATH_PROPERTY

public static final String LEAD_SELECTION_PATH_PROPERTY
Since:
1.3
See Also:
Constant Field Values

EXPANDS_SELECTED_PATHS_PROPERTY

public static final String EXPANDS_SELECTED_PATHS_PROPERTY
Since:
1.3
See Also:
Constant Field Values

cellEditor

protected transient TreeCellEditor cellEditor

cellRenderer

protected transient 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 transient TreeSelectionModel selectionModel

showsRootHandles

protected boolean showsRootHandles

toggleClickCount

protected int toggleClickCount

treeModel

protected transient TreeModel treeModel

visibleRowCount

protected int visibleRowCount

treeModelListener

protected transient TreeModelListener treeModelListener
Handles TreeModelEvents to update the expandedState.


selectionRedirector

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

Constructor Detail

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(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.

JTree

public JTree(Vector<?> value)
Creates a new JTree object.

Parameters:
value - the initial nodes in the tree
Method Detail

getRowForPath

public int getRowForPath(TreePath path)

getPathForRow

public TreePath getPathForRow(int row)

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

createTreeModel

protected static TreeModel createTreeModel(Object value)
Creates a new TreeModel object.

Parameters:
value - the values stored in the model

getUI

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

Returns:
the associated TreeUI object

setUI

public void setUI(TreeUI ui)
Sets the UI associated with this JTree object.

Parameters:
ui - the TreeUI to associate

updateUI

public void updateUI()
This method resets the UI used to the Look and Feel defaults..

Overrides:
updateUI in class JComponent

getUIClassID

public String getUIClassID()
This method returns the String ID of the UI class of Separator.

Overrides:
getUIClassID in class JComponent
Returns:
The UI class' String ID.
See Also:
JComponent.setUI(javax.swing.plaf.ComponentUI), JComponent.updateUI()

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this JTree.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class JComponent
Returns:
the associated context

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Returns the preferred viewport size.

Specified by:
getPreferredScrollableViewportSize in interface Scrollable
Returns:
the preferred size

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.
Returns:
the preferred scrolling distance, negative if up or left.

getScrollableBlockIncrement

public int getScrollableBlockIncrement(Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Description copied from interface: Scrollable
Return the preferred scrolling amount (in pixels) for the given scrolling direction and orientation when scrolling in large amounts (pages).

Specified by:
getScrollableBlockIncrement 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.
Returns:
the preferred scrolling distance, negative if up or left.

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Description copied from interface: Scrollable
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.

Specified by:
getScrollableTracksViewportHeight in interface Scrollable
Returns:
true is no horizontal scrolling is assumed, faster otherwise.

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Description copied from interface: Scrollable
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). In such case, the horizontal scrolling should not be performed.

Specified by:
getScrollableTracksViewportWidth in interface Scrollable
Returns:
true is no horizontal scrolling is assumed, faster otherwise.

addTreeExpansionListener

public void addTreeExpansionListener(TreeExpansionListener listener)
Adds a TreeExpansionListener object to the tree.

Parameters:
listener - the listener to add

removeTreeExpansionListener

public void removeTreeExpansionListener(TreeExpansionListener listener)
Removes a TreeExpansionListener object from the tree.

Parameters:
listener - the listener to remove

getTreeExpansionListeners

public TreeExpansionListener[] getTreeExpansionListeners()
Returns all added TreeExpansionListener objects.

Returns:
an array of listeners

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

addTreeSelectionListener

public void addTreeSelectionListener(TreeSelectionListener listener)
Adds a TreeSelctionListener object to the tree.

Parameters:
listener - the listener to add

removeTreeSelectionListener

public void removeTreeSelectionListener(TreeSelectionListener listener)
Removes a TreeSelectionListener object from the tree.

Parameters:
listener - the listener to remove

getTreeSelectionListeners

public TreeSelectionListener[] getTreeSelectionListeners()
Returns all added TreeSelectionListener objects.

Returns:
an array of listeners

fireValueChanged

protected void fireValueChanged(TreeSelectionEvent event)
Notifies all listeners when the selection of the tree changed.

Parameters:
event - the event to send

addTreeWillExpandListener

public void addTreeWillExpandListener(TreeWillExpandListener listener)
Adds a TreeWillExpandListener object to the tree.

Parameters:
listener - the listener to add

removeTreeWillExpandListener

public void removeTreeWillExpandListener(TreeWillExpandListener listener)
Removes a TreeWillExpandListener object from the tree.

Parameters:
listener - the listener to remove

getTreeWillExpandListeners

public TreeWillExpandListener[] getTreeWillExpandListeners()
Returns all added TreeWillExpandListener objects.

Returns:
an array of listeners

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
Throws:
ExpandVetoException

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
Throws:
ExpandVetoException

getModel

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

Returns:
the associated TreeModel

setModel

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

Parameters:
model - the TreeModel to use

isEditable

public boolean isEditable()
Checks if this JTree object is editable.

Returns:
true if this tree object is editable, false otherwise

setEditable

public void setEditable(boolean flag)
Sets the editable property.

Parameters:
flag - true to make this tree object editable, false otherwise

isRootVisible

public boolean isRootVisible()
Checks if the root element is visible.

Returns:
true if the root element is visible, false otherwise

setRootVisible

public void setRootVisible(boolean flag)

getShowsRootHandles

public boolean getShowsRootHandles()

setShowsRootHandles

public void setShowsRootHandles(boolean flag)

getCellEditor

public TreeCellEditor getCellEditor()

setCellEditor

public void setCellEditor(TreeCellEditor editor)

getCellRenderer

public TreeCellRenderer getCellRenderer()

setCellRenderer

public void setCellRenderer(TreeCellRenderer newRenderer)

getSelectionModel

public TreeSelectionModel getSelectionModel()

setSelectionModel

public void setSelectionModel(TreeSelectionModel model)

getVisibleRowCount

public int getVisibleRowCount()

setVisibleRowCount

public void setVisibleRowCount(int rows)

isLargeModel

public boolean isLargeModel()

setLargeModel

public void setLargeModel(boolean large)

getRowHeight

public int getRowHeight()

setRowHeight

public void setRowHeight(int height)

isFixedRowHeight

public boolean isFixedRowHeight()

getInvokesStopCellEditing

public boolean getInvokesStopCellEditing()

setInvokesStopCellEditing

public void setInvokesStopCellEditing(boolean invoke)

getToggleClickCount

public int getToggleClickCount()
Since:
1.3

setToggleClickCount

public void setToggleClickCount(int count)
Since:
1.3

scrollPathToVisible

public void scrollPathToVisible(TreePath path)

scrollRowToVisible

public void scrollRowToVisible(int row)

getScrollsOnExpand

public boolean getScrollsOnExpand()

setScrollsOnExpand

public void setScrollsOnExpand(boolean scroll)

setSelectionPath

public void setSelectionPath(TreePath path)

setSelectionPaths

public void setSelectionPaths(TreePath[] paths)

setSelectionRow

public void setSelectionRow(int row)

setSelectionRows

public void setSelectionRows(int[] rows)

setSelectionInterval

public void setSelectionInterval(int index0,
                                 int index1)

addSelectionPath

public void addSelectionPath(TreePath path)

addSelectionPaths

public void addSelectionPaths(TreePath[] paths)

addSelectionRow

public void addSelectionRow(int row)

addSelectionRows

public void addSelectionRows(int[] rows)

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

removeSelectionPath

public void removeSelectionPath(TreePath path)

removeSelectionPaths

public void removeSelectionPaths(TreePath[] paths)

removeSelectionRow

public void removeSelectionRow(int row)

removeSelectionRows

public void removeSelectionRows(int[] rows)

removeSelectionInterval

public void removeSelectionInterval(int index0,
                                    int index1)

clearSelection

public void clearSelection()

getLeadSelectionPath

public TreePath getLeadSelectionPath()

setLeadSelectionPath

public void setLeadSelectionPath(TreePath path)
Since:
1.3

getAnchorSelectionPath

public TreePath getAnchorSelectionPath()
Since:
1.3

setAnchorSelectionPath

public void setAnchorSelectionPath(TreePath path)
Since:
1.3

getLeadSelectionRow

public int getLeadSelectionRow()

getMaxSelectionRow

public int getMaxSelectionRow()

getMinSelectionRow

public int getMinSelectionRow()

getSelectionCount

public int getSelectionCount()

getSelectionPath

public TreePath getSelectionPath()

getSelectionPaths

public TreePath[] getSelectionPaths()

getSelectionRows

public int[] getSelectionRows()

isPathSelected

public boolean isPathSelected(TreePath path)

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()

getDragEnabled

public boolean getDragEnabled()
Return the value of the dragEnabled property.

Returns:
the value
Since:
1.4

setDragEnabled

public void setDragEnabled(boolean enabled)
Set the dragEnabled property.

Parameters:
enabled - new value
Since:
1.4

getRowCount

public int getRowCount()

collapsePath

public void collapsePath(TreePath path)

collapseRow

public void collapseRow(int row)

expandPath

public void expandPath(TreePath path)

expandRow

public void expandRow(int row)

isCollapsed

public boolean isCollapsed(TreePath path)

isCollapsed

public boolean isCollapsed(int row)

isExpanded

public boolean isExpanded(TreePath path)

isExpanded

public boolean isExpanded(int row)

getExpandsSelectedPaths

public boolean getExpandsSelectedPaths()
Since:
1.3

setExpandsSelectedPaths

public void setExpandsSelectedPaths(boolean flag)
Since:
1.3

getPathBounds

public Rectangle getPathBounds(TreePath path)

getRowBounds

public Rectangle getRowBounds(int row)

isEditing

public boolean isEditing()

stopEditing

public boolean stopEditing()

cancelEditing

public void cancelEditing()

startEditingAtPath

public void startEditingAtPath(TreePath path)

getEditingPath

public TreePath getEditingPath()

getPathForLocation

public TreePath getPathForLocation(int x,
                                   int y)

getRowForLocation

public int getRowForLocation(int x,
                             int y)

getClosestPathForLocation

public TreePath getClosestPathForLocation(int x,
                                          int y)

getClosestRowForLocation

public int getClosestRowForLocation(int x,
                                    int y)

getLastSelectedPathComponent

public Object getLastSelectedPathComponent()

setExpandedState

protected void setExpandedState(TreePath path,
                                boolean state)

clearToggledPaths

protected void clearToggledPaths()

getDescendantToggledPaths

protected Enumeration<TreePath> getDescendantToggledPaths(TreePath parent)

hasBeenExpanded

public boolean hasBeenExpanded(TreePath path)

isVisible

public boolean isVisible(TreePath path)

makeVisible

public void makeVisible(TreePath path)

isPathEditable

public boolean isPathEditable(TreePath path)

createTreeModelListener

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

Returns:
an instance of JTree.TreeModelHandler

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

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

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 class JComponent
Returns:
a String representation of this JTree

getExpandedDescendants

public Enumeration<TreePath> 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

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

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<TreePath> 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.

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.

See Also:
DefaultTreeModel.reload()