javax.swing.tree

Class TreePath

public class TreePath extends Object implements Serializable

A TreePath represents a sequence of tree elements that form a path starting from the root of a tree. A tree element can be represented by any {@link Object}.
Constructor Summary
TreePath(Object[] path)
Creates a path from the list of objects representing tree elements.
TreePath(Object element)
Creates a new path from a single element.
protected TreePath(TreePath path, Object element)
Creates a new tree path by adding the specified element to the path.
protected TreePath(Object[] path, int length)
Creates a new tree path using the first length elements from the given array.
protected TreePath()
Default constructor.
Method Summary
booleanequals(Object object)
Tests this path for equality with an arbitrary object.
ObjectgetLastPathComponent()
Returns the last object in the path.
TreePathgetParentPath()
Returns the parent path, which is a path containing all the same elements as this path, except for the last one.
Object[]getPath()
Returns an array containing the path elements.
ObjectgetPathComponent(int position)
Returns the element at the specified position in the path.
intgetPathCount()
Returns the number of elements in the path.
inthashCode()
Returns a hashcode for the path.
booleanisDescendant(TreePath path)
Returns true if path is a descendant of this path, and false otherwise.
TreePathpathByAddingChild(Object element)
Creates a new path that is equivalent to this path plus the specified element.
StringtoString()
Returns a string representation of this path.

Constructor Detail

TreePath

public TreePath(Object[] path)
Creates a path from the list of objects representing tree elements. The incoming array is copied so that subsequent changes do not affect this tree path.

Parameters: path the elements in the path (null not permitted).

Throws: IllegalArgumentException if path is null.

TreePath

public TreePath(Object element)
Creates a new path from a single element.

Parameters: element the element (null not permitted).

Throws: IllegalArgumentException if element is null.

TreePath

protected TreePath(TreePath path, Object element)
Creates a new tree path by adding the specified element to the path.

Parameters: path a tree path. element a path element.

TreePath

protected TreePath(Object[] path, int length)
Creates a new tree path using the first length elements from the given array.

Parameters: path the path elements. length the path length.

TreePath

protected TreePath()
Default constructor.

Method Detail

equals

public boolean equals(Object object)
Tests this path for equality with an arbitrary object. An object is considered equal to this path if and only if:

Parameters: object the object (null permitted).

Returns: true if obj is equal to this tree path, and false otherwise.

getLastPathComponent

public Object getLastPathComponent()
Returns the last object in the path.

Returns: The last object in the path.

getParentPath

public TreePath getParentPath()
Returns the parent path, which is a path containing all the same elements as this path, except for the last one. If this path contains only one element, the method returns null.

Returns: The parent path, or null if this path has only one element.

getPath

public Object[] getPath()
Returns an array containing the path elements.

Returns: An array containing the path elements.

getPathComponent

public Object getPathComponent(int position)
Returns the element at the specified position in the path.

Parameters: position the element position (0 < N - 1, where N is the number of elements in the path).

Returns: The element at the specified position.

Throws: IllegalArgumentException if position is outside the valid range.

getPathCount

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

Returns: The number of elements in the path.

hashCode

public int hashCode()
Returns a hashcode for the path.

Returns: A hashcode.

isDescendant

public boolean isDescendant(TreePath path)
Returns true if path is a descendant of this path, and false otherwise. If path is null, this method returns false.

Parameters: path the path to check (null permitted).

Returns: true if path is a descendant of this path, and false otherwise

pathByAddingChild

public TreePath pathByAddingChild(Object element)
Creates a new path that is equivalent to this path plus the specified element.

Parameters: element the element.

Returns: A tree path.

toString

public String toString()
Returns a string representation of this path.

Returns: A string representation of this path.