JBTreeTraverser<TreePath> (@NotNull JTree tree) { TreeModel model = tree.getModel(); Object root = model.getRoot(); TreePath rootPath = root == null ? null : new TreePath(root); return JBTreeTraverser.<TreePath>from(path -> nodeChildren(path.getLastPathComponent(), model) .map(o -> path.pathByAddingChild(o))) .withRoot(rootPath); }