The interface that defines a suitable data model for a JTree. For further information on tree models, including an example of a custom implementation, see How to Use Trees in The Java Tutorial.
JTree and its related classes make extensive use of TreePaths for indentifying nodes in the TreeModel. If a TreeModel returns the same object, as compared by equals, at two different indices under the same parent than 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.
Method Summary | |
---|---|
void |
addTreeModelListener
(
TreeModelListener
l) Adds a listener for the TreeModelEvent posted after the tree changes. |
Object |
getChild
(
Object
parent, int index) Returns the child of parent at index index in the parent's child array. |
int |
getChildCount
(
Object
parent) Returns the number of children of parent. |
int |
getIndexOfChild
(
Object
parent,
Object
child) Returns the index of child in parent. |
Object |
getRoot
() Returns the root of the tree. |
boolean |
isLeaf
(
Object
node) Returns true if node is a leaf. |
void |
removeTreeModelListener
(
TreeModelListener
l) Removes a listener previously added with addTreeModelListener. |
void |
valueForPathChanged
(
TreePath
path,
Object
newValue) Messaged when the user has altered the value for the item identified by path to newValue. |
Method Detail |
---|
Object getRoot()
Object getChild(Object parent, int index)
int getChildCount(Object parent)
boolean isLeaf(Object node)
void valueForPathChanged(TreePath path, Object newValue)
int getIndexOfChild(Object parent, Object child)
void addTreeModelListener(TreeModelListener l)
void removeTreeModelListener(TreeModelListener l)