void (final @Nullable JTree tree) { if (tree == null) return; Runnable runnable = () -> { TreeModel model = tree.getModel(); Object root = model.getRoot(); if (root == null) return; TreePath rootPath = new TreePath(root); tree.expandPath(rootPath); if (model.getChildCount(root) == 1) { Object firstChild = model.getChild(root, 0); tree.expandPath(rootPath.pathByAddingChild(firstChild)); } }; EdtInvocationManager.invokeLaterIfNeeded(runnable); }