List of utility methods to do JTree Path
TreePath | getTreePath(TreePath path, JTree tree, boolean compareOnlyLabels) get Tree Path Object[] pathElements = path.getPath(); TreePath result = null; TreeNode root = (TreeNode) tree.getModel().getRoot(); if ((root.toString() == null && pathElements[0].toString() == null) || (root.toString().compareTo(pathElements[0].toString()) == 0)) result = new TreePath(root); if (result == null || pathElements.length == 1) return result; ... |
String | getTreePathString(TreePath path) get Tree Path String return path.toString();
|
TreePath[] | getUpdatedTreePath(TreePath[] paths, JTree tree) get Updated Tree Path if (paths == null || tree == null) { return null; 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) { ... |
Object | getUserObject(TreePath path) get User Object Object value = path.getLastPathComponent(); if (value instanceof DefaultMutableTreeNode) { return ((DefaultMutableTreeNode) value).getUserObject(); return value; |
Object | getUserObject(TreePath path) get User Object Object value = path.getLastPathComponent(); if (value instanceof DefaultMutableTreeNode) { return ((DefaultMutableTreeNode) value).getUserObject(); return value; |
boolean | isDescendant(TreePath path1, final TreePath path2) is Descendant int count1 = path1.getPathCount(); final int count2 = path2.getPathCount(); if (count1 <= count2) { return false; while (count1 != count2) { path1 = path1.getParentPath(); count1--; ... |
boolean | isDescendant(TreePath path1, final TreePath path2) Is path1 descendant of path2? int count1 = path1.getPathCount(); final int count2 = path2.getPathCount(); if (count1 <= count2) { return false; while (count1 != count2) { path1 = path1.getParentPath(); count1--; ... |
boolean | isFile(TreePath path) is File DefaultMutableTreeNode clickedNode = (DefaultMutableTreeNode) path.getLastPathComponent();
return (!clickedNode.getAllowsChildren());
|
boolean | isSource(TreePath path) is Source int pathCount = path.getPathCount(); return (pathCount == 2); |
boolean | isTreePathContainedInExpansionState(TreePath treePath, ArrayList is Tree Path Contained In Expansion State if (treePath != null && expansionStateStrings != null) { return expansionStateStrings.contains(treePath.toString()); return false; |