Example #1
0
 public static void unselect(JTree tree, final DefaultMutableTreeNode node) {
   final TreePath rootPath = new TreePath(node.getPath());
   final TreePath[] selectionPaths = tree.getSelectionPaths();
   if (selectionPaths != null) {
     for (TreePath selectionPath : selectionPaths) {
       if (selectionPath.getPathCount() > rootPath.getPathCount()
           && rootPath.isDescendant(selectionPath)) {
         tree.removeSelectionPath(selectionPath);
       }
     }
   }
 }
Example #2
0
 public static List<TreePath> collectSelectedPaths(final JTree tree, final TreePath treePath) {
   final ArrayList<TreePath> result = new ArrayList<TreePath>();
   final TreePath[] selections = tree.getSelectionPaths();
   if (selections != null) {
     for (TreePath selection : selections) {
       if (treePath.isDescendant(selection)) {
         result.add(selection);
       }
     }
   }
   return result;
 }