void () { myPathsToExpand = new ArrayList<>(); mySelectionPaths = new ArrayList<>(); DefaultMutableTreeNode root = (DefaultMutableTreeNode)myTree.getModel().getRoot(); TreePath path = new TreePath(root.getPath()); if (myTree.isPathSelected(path)) { addPathToList(root, mySelectionPaths); } if (myTree.isExpanded(path) || root.getChildCount() == 0) { addPathToList(root, myPathsToExpand); _storePaths(root); } }