Java JTree Path findTreePath(TreePath path, TreeNode node, String pathName)

Here you can find the source of findTreePath(TreePath path, TreeNode node, String pathName)

Description

find Tree Path

License

Apache License

Declaration

private static TreePath findTreePath(TreePath path, TreeNode node, String pathName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Enumeration;

import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

public class Main {
    private static TreePath findTreePath(TreePath path, TreeNode node, String pathName) {
        if (path == null || pathName == null || node == null) {
            return null;
        }// ww  w .  j  a  va 2 s.com

        if (pathName.equals(getTreePathString(path))) {
            return path;
        }

        if (node.getChildCount() >= 0) {
            for (Enumeration<?> e = node.children(); e.hasMoreElements();) {
                TreeNode child = (TreeNode) e.nextElement();
                TreePath childPath = path.pathByAddingChild(child);
                TreePath childMatch = findTreePath(childPath, child, pathName);
                if (childMatch != null) {
                    return childMatch;
                }
            }
        }

        return null;
    }

    private static String getTreePathString(TreePath path) {
        return path.toString();
    }
}

Related

  1. createTreePath(TreeNode treeNode)
  2. createTreePathFromTreeNode(TreeNode treeNode)
  3. doNode(JTree tree, TreeNode parentNode, TreePath parentPath)
  4. find2(JTree tree, TreePath parent, Object[] nodes, int depth, boolean byName)
  5. findOrAddNode(JTree tree, TreePath parent, String packageName)
  6. findV2MetaTreeNode( String nodeXmlPath)
  7. getDepth(JTree tree)
  8. getExpatnedTreePaths(JTree tree)
  9. getObjectPathForNode(final TreeNode node)