TreePath (JTree tree, TreePath treePath) { List<String> path = new ArrayList<>(); for (int i = 0; i < treePath.getPath().length; i++) { Group group = getGroupForNode((DefaultMutableTreeNode)treePath.getPath()[i]); if (group != null) { path.add(group.getName()); } } return getTreePath(0, path, tree.getModel().getRoot()); }