void (TreeModelEvent e) { final TreePath p = e.getTreePath(); if (p != null) { if (p.getPathCount() > 1) { final Runnable runnable = () -> { DefaultMutableTreeNode last = (DefaultMutableTreeNode)p.getLastPathComponent(); if (last.getChildCount() > 0) { DefaultMutableTreeNode next = (DefaultMutableTreeNode)last.getFirstChild(); while (next != null) { myEventTree.collapsePath(TreeUtil.getPathFromRoot(next)); next = next.getNextSibling(); } } }; ApplicationManager.getApplication().invokeLater(runnable); } } }