void () { DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); DefaultTreeModel model = new DefaultTreeModel(root) { @Override public void removeNodeFromParent(MutableTreeNode mutableTreeNode) { super.removeNodeFromParent((MutableTreeNode) mutableTreeNode.getParent()); } }; DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("1"); model.insertNodeInto(node1, root, 0); DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("2"); model.insertNodeInto(node2, node1, 0); JTree tree = new Tree(model); TreeTestUtil.assertTreeUI(tree); TreeExpandCollapse.expandAll(tree); tree.setSelectionPath(TreeUtil.getPathFromRoot(node2)); TreeUtil.removeSelected(tree); assertEquals(0, root.getChildCount()); assertEquals(root, tree.getSelectionPath().getLastPathComponent()); }