JTree.
JTree and its related classes make extensive use of
TreePaths for identifying nodes in the TreeModel.
If a TreeModel returns the same object, as compared by
equals, at two different indices under the same parent
then the resulting TreePath objects will be considered equal
as well. Some implementations may assume that if two
TreePaths are equal, they identify the same node. If this
condition is not met, painting problems and other oddities may result.
In other words, if getChild for a given parent returns
the same Object (as determined by equals) problems may
result, and it is recommended you avoid doing this.
Similarly JTree and its related classes place
TreePaths in Maps. As such if
a node is requested twice, the return values must be equal
(using the equals method) and have the same
hashCode.
For further information on tree models, including an example of a custom implementation, see How to Use Trees in The Java Tutorial.
TreePath
| Modifier and Type | Method and Description |
|---|---|
| public void | addTreeModelListener(TreeModelListener
the listener to add l)Adds a listener for the |
| public Object | |
| public int | Returns: the number of children of the nodeparenta node in the tree, obtained from this data source parent)Returns the number of children of |
| public int | Returns: the index of the child in the parent, or -1 if eitherchild or parent are null
or don't belong to this tree modela node in the tree, obtained from this data source parent, Object the node we are interested in child)Returns the index of child in parent. |
| public Object | |
| public boolean | |
| public void | removeTreeModelListener(TreeModelListener
the listener to remove l)Removes a listener previously added with
|
| public void | valueForPathChanged(TreePath
path to the node that the user has altered path, Object the new value from the TreeCellEditor newValue)Messaged when the user has altered the value for the item identified
by |
| addTreeModelListener | back to summary |
|---|---|
| public void addTreeModelListener(TreeModelListener l) Adds a listener for the
| |
| getChild | back to summary |
|---|---|
| public Object getChild(Object parent, int index) Returns the child of | |
| getChildCount | back to summary |
|---|---|
| public int getChildCount(Object parent) Returns the number of children of
| |
| getIndexOfChild | back to summary |
|---|---|
| public int getIndexOfChild(Object parent, Object child) Returns the index of child in parent. If either | |
| getRoot | back to summary |
|---|---|
| public Object getRoot() Returns the root of the tree. Returns
| |
| isLeaf | back to summary |
|---|---|
| public boolean isLeaf(Object node) Returns
| |
| removeTreeModelListener | back to summary |
|---|---|
| public void removeTreeModelListener(TreeModelListener l) Removes a listener previously added with
| |
| valueForPathChanged | back to summary |
|---|---|
| public void valueForPathChanged(TreePath path, Object newValue) Messaged when the user has altered the value for the item identified
by | |