Java JTree Path makeTreePath(TreeNode treeNode)

Here you can find the source of makeTreePath(TreeNode treeNode)

Description

Creates a tree path from the root node of the tree to the specified treeNode instance

License

Open Source License

Declaration

public static TreePath makeTreePath(TreeNode treeNode) 

Method Source Code

//package com.java2s;
/*//from  w w w. j  a v  a  2  s.  com
 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
 * 
 * This software is open source. 
 * See the bottom of this file for the licence.
 * 
 * $Id: TreeNodeHelper.java,v 1.1.1.1 2001/05/22 08:12:55 jstrachan Exp $
 */

import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import java.util.LinkedList;

public class Main {
    /** Creates a tree path from the root node of the tree to the specified treeNode instance
      */
    public static TreePath makeTreePath(TreeNode treeNode) {
        LinkedList list = new LinkedList();

        while (treeNode != null) {
            list.addFirst(treeNode);
            treeNode = treeNode.getParent();
        }

        Object[] nodes = list.toArray();
        return new TreePath(nodes);
    }
}

Related

  1. isSource(TreePath path)
  2. isTreePathContainedInExpansionState(TreePath treePath, ArrayList expansionStateStrings)
  3. lastPathComponents(TreePath[] paths)
  4. loadExpansionState(JTree tree, Enumeration expansionState)
  5. makeLocalFilePath(TreePath treePath)
  6. pathByAddingChildAsStr(TreePath currPath, String child)
  7. pathContains(TreePath[] paths, Class clazz)
  8. pathToDepth(TreePath path, int depth)
  9. resourceFromTreePath(TreePath path)