Here you can find the source of findTreePath(TreePath path, TreeNode node, String pathName)
private static TreePath findTreePath(TreePath path, TreeNode node, String pathName)
//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(); } }