![]() |
The Java Developers Almanac 1.4 |
|
e1027. Converting a Node in a JTree Component to a TreePath // Returns a TreePath containing the specified node.
public TreePath getPath(TreeNode node) {
List list = new ArrayList();
// Add all nodes to list
while (node != null) {
list.add(node);
node = node.getParent();
}
Collections.reverse(list);
// Convert array of nodes to TreePath
return new TreePath(list.toArray());
}
e1024. Finding a Node in a JTree Component e1025. Adding a Node to a JTree Component e1026. Removing a Node to a JTree Component e1028. Converting All Nodes in a JTree Component to a TreePath Array
© 2002 Addison-Wesley. |