The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing.tree  [15 examples] > Nodes  [6 examples]

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

 Related Examples
e1023. Visiting All the Nodes in a JTree Component
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

See also: Events    Layout    Node Expansion    Selections   


© 2002 Addison-Wesley.