List<Navigatable> () { TreePath[] paths = myTree.getSelectionPaths(); if (paths == null) return Collections.emptyList(); final ArrayList<Navigatable> navigatables = new ArrayList<>(); for (TreePath path : paths) { Object lastPathComponent = path.getLastPathComponent(); if (lastPathComponent instanceof DefaultMutableTreeNode node) { Object userObject = node.getUserObject(); if (userObject instanceof Navigatable) { navigatables.add((Navigatable)userObject); } else if (node instanceof Navigatable) { navigatables.add((Navigatable)node); } } } return navigatables; }