void (final String actionId) { Object root = myTree.getModel().getRoot(); if (!(root instanceof CheckedTreeNode)) { return; } final List<CheckedTreeNode> nodes = new ArrayList<>(); new Object() { public void collect(CheckedTreeNode node) { if (node.isLeaf()) { Object userObject = node.getUserObject(); if (userObject instanceof Tool && actionId.equals(((Tool)userObject).getActionId())) { nodes.add(node); } } else { for (int i = 0; i < node.getChildCount(); i++) { final TreeNode child = node.getChildAt(i); if (child instanceof CheckedTreeNode) { collect((CheckedTreeNode)child); } } } } }.collect((CheckedTreeNode)root); if (nodes.isEmpty()) { return; } myTree.getSelectionModel().setSelectionPath(new TreePath(nodes.get(0).getPath())); }