void () { for (DefaultMutableTreeNode node : getNodesByPaths(myPathsToExpand)) { myTree.expandPath(new TreePath(node.getPath())); } if (myTree.getSelectionModel().getSelectionCount() == 0) { List<DefaultMutableTreeNode> nodesToSelect = getNodesByPaths(mySelectionPaths); if (!nodesToSelect.isEmpty()) { for (DefaultMutableTreeNode node : nodesToSelect) { TreeUtil.selectNode(myTree, node); } } else { myTree.setSelectionRow(0); } } }