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());
}
Post a comment