void () { DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); DefaultTreeModel model = new DefaultTreeModel(root); DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("1"); model.insertNodeInto(child1, root, 0); DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("2"); model.insertNodeInto(child2, root, 1); DefaultMutableTreeNode child11 = new DefaultMutableTreeNode("11"); model.insertNodeInto(child11, child1, 0); JTree tree = new Tree(model); TreeTestUtil.assertTreeUI(tree); TreeExpandCollapse.expandAll(tree); tree.clearSelection(); TreeUtil.removeSelected(tree); assertEquals(2, model.getChildCount(root)); assertEquals(1, model.getChildCount(child1)); tree.setSelectionPath(TreeUtil.getPathFromRoot(child11)); TreeUtil.removeSelected(tree); assertSame(child1, tree.getSelectionPath().getLastPathComponent()); TreeUtil.removeSelected(tree); assertSame(child2, tree.getSelectionPath().getLastPathComponent()); tree.setSelectionPath(new TreePath(root)); assertEquals(1, model.getChildCount(root)); TreeUtil.removeSelected(tree); assertSame(root, model.getRoot()); assertEquals(1, model.getChildCount(root)); }