Java JTree Path getPath(TreeNode treeNode)

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

Description

get Path

License

Open Source License

Declaration

public static TreePath getPath(TreeNode treeNode) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

import java.util.List;

public class Main {
    public static TreePath getPath(TreeNode treeNode) {
        List<Object> nodes = new ArrayList<Object>();
        if (treeNode != null) {
            nodes.add(treeNode);/*from w w w .  java2  s . co  m*/
            treeNode = treeNode.getParent();
            while (treeNode != null) {
                nodes.add(0, treeNode);
                treeNode = treeNode.getParent();
            }
        }

        return nodes.isEmpty() ? null : new TreePath(nodes.toArray());
    }
}

Related

  1. getDepth(JTree tree)
  2. getExpatnedTreePaths(JTree tree)
  3. getObjectPathForNode(final TreeNode node)
  4. getPath(TreeNode node)
  5. getPath(TreeNode treeNode)
  6. getPath(TreeNode treeNode)
  7. getPath(TreeNode treeNode)
  8. getPathStr(TreeNode[] projectNodes)
  9. getTree(List paths)