Here you can find the source of getUpdatedTreePath(TreePath[] paths, JTree tree)
public static TreePath[] getUpdatedTreePath(TreePath[] paths, JTree tree)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Enumeration; import javax.swing.JTree; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; public class Main { public static TreePath[] getUpdatedTreePath(TreePath[] paths, JTree tree) { if (paths == null || tree == null) { return null; }/*from w w w. ja va2 s .c o m*/ TreeNode root = (TreeNode) tree.getModel().getRoot(); ArrayList<TreePath> result = new ArrayList<TreePath>(); for (int i = 0; i < paths.length; i++) { TreePath updatedPath = findTreePath(new TreePath(root), root, getTreePathString(paths[i])); if (updatedPath != null) { result.add(updatedPath); } } return result.toArray(new TreePath[result.size()]); } private static TreePath findTreePath(TreePath path, TreeNode node, String pathName) { if (path == null || pathName == null || node == null) { return null; } 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(); } }