void (TreeExpansionEvent event) { TreePath path = event.getPath(); TreeModel model = tree.getModel(); Object lastPathComponent = path.getLastPathComponent(); int childCount = model.getChildCount(lastPathComponent); for (int i = 0; i < childCount; i++) { Object child = model.getChild(lastPathComponent, i); TreePath childPath = path.pathByAddingChild(child); if (tree.isExpanded(childPath)) { tree.collapsePath(childPath); } } }