void (ActionEvent event) { Object source = event.getSource(); if (source instanceof JTree tree) { TreePath path = tree.getLeadSelectionPath(); if (path != null) { if (tree.isExpanded(path) || tree.getModel().isLeaf(path.getLastPathComponent())) { int row = tree.getRowForPath(path); path = row < 0 ? null : tree.getPathForRow(row + 1); if (path != null) { tree.setSelectionPath(path); tree.scrollPathToVisible(path); } } else { tree.expandPath(path); } } } }