This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


javax.swing.tree
class TreePath

java.lang.Object extended by javax.swing.tree.TreePath
All Implemented Interfaces:
Serializable

Most common way to construct:

JTree tree = …;

TreePath currentSelection = tree.getSelectionPath();

Based on 29 examples


public class TreePath
extends Object
implements Serializable

Represents a path to a node. A TreePath is an array of Objects that are vended from a TreeModel. The elements of the array are ordered such that the root is always the first element (index 0) of the array. TreePath is Serializable, but if any components of the path are not serializable, it will not be written out.

For further information and examples of using tree paths, see How to Use Trees in The Java Tutorial.

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


Constructor Summary
protected

          Primarily provided for subclasses that represent paths in a different manner.
 
TreePath(Object singlePath)

          Constructs a TreePath containing only a single element.
 
TreePath(Object[] path)

          Constructs a path from an array of Objects, uniquely identifying the path from the root of the tree to a specific node, as returned by the tree's data model.
protected
TreePath(Object[] path, int length)

          Constructs a new TreePath with the identified path components of length length.
protected
TreePath(TreePath parent, Object lastElement)

          Constructs a new TreePath, which is the path identified by parent ending in lastElement.
 
Method Summary
 boolean

          Tests two TreePaths for equality by checking each element of the paths for equality.
 Object

          Returns the last component of this path.
 TreePath

          Returns a path containing all the elements of this object, except the last path component.
 Object[]

          Returns an ordered array of Objects containing the components of this TreePath.
 Object
getPathComponent(int element)

          Returns the path component at the specified index.
 int

          Returns the number of elements in the path.
 int

          Returns the hashCode for the object.
 boolean

          Returns true if aTreePath is a descendant of this TreePath.
 TreePath

          Returns a new path containing all the elements of this object plus child.
 String

          Returns a string that displays and identifies this object's properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreePath

protected TreePath()
Primarily provided for subclasses that represent paths in a different manner. If a subclass uses this constructor, it should also override the getPath, getPathCount, and getPathComponent methods, and possibly the equals method.


TreePath

public TreePath(Object singlePath)
Constructs a TreePath containing only a single element. This is usually used to construct a TreePath for the the root of the TreeModel.

Parameters:
singlePath - an Object representing the path to a node

TreePath

public TreePath(Object[] path)
Constructs a path from an array of Objects, uniquely identifying the path from the root of the tree to a specific node, as returned by the tree's data model.

The model is free to return an array of any Objects it needs to represent the path. The DefaultTreeModel returns an array of TreeNode objects. The first TreeNode in the path is the root of the tree, the last TreeNode is the node identified by the path.

Parameters:
path - an array of Objects representing the path to a node

TreePath

protected TreePath(Object[] path,
                   int length)
Constructs a new TreePath with the identified path components of length length.

Parameters:
path
length

TreePath

protected TreePath(TreePath parent,
                   Object lastElement)
Constructs a new TreePath, which is the path identified by parent ending in lastElement.

Parameters:
parent
lastElement
Method Detail

equals

public boolean equals(Object o)
Tests two TreePaths for equality by checking each element of the paths for equality. Two paths are considered equal if they are of the same length, and contain the same elements (.equals).

Overrides:
equals in class Object
Parameters:
o - the Object to compare

getLastPathComponent

public Object getLastPathComponent()
Returns the last component of this path. For a path returned by DefaultTreeModel this will return an instance of TreeNode.

Returns:
the Object at the end of the path

getParentPath

public TreePath getParentPath()
Returns a path containing all the elements of this object, except the last path component.


getPath

public Object[] getPath()
Returns an ordered array of Objects containing the components of this TreePath. The first element (index 0) is the root.

Returns:
an array of Objects representing the TreePath

getPathComponent

public Object getPathComponent(int element)
Returns the path component at the specified index.

Parameters:
element - an int specifying an element in the path, where 0 is the first element in the path
Returns:
the Object at that index location

getPathCount

public int getPathCount()
Returns the number of elements in the path.

Returns:
an int giving a count of items the path

hashCode

public int hashCode()
Returns the hashCode for the object. The hash code of a TreePath is defined to be the hash code of the last component in the path.

Overrides:
hashCode in class Object
Returns:
the hashCode for the object

isDescendant

public boolean isDescendant(TreePath aTreePath)
Returns true if aTreePath is a descendant of this TreePath. A TreePath P1 is a descendant of a TreePath P2 if P1 contains all of the components that make up P2's path. For example, if this object has the path [a, b], and aTreePath has the path [a, b, c], then aTreePath is a descendant of this object. However, if aTreePath has the path [a], then it is not a descendant of this object. By this definition a TreePath is always considered a descendant of itself. That is, aTreePath.isDescendant(aTreePath) returns true.

Parameters:
aTreePath
Returns:
true if aTreePath is a descendant of this path

pathByAddingChild

public TreePath pathByAddingChild(Object child)
Returns a new path containing all the elements of this object plus child. child will be the last element of the newly created TreePath. This will throw a NullPointerException if child is null.

Parameters:
child

toString

public String toString()
Returns a string that displays and identifies this object's properties.

Overrides:
toString in class Object
Returns:
a String representation of this object


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.