void () { DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); DefaultTreeModel model = new DefaultTreeModel(root); model.insertNodeInto(new DefaultMutableTreeNode("1"), root, 0); DefaultMutableTreeNode middle = new DefaultMutableTreeNode("2"); model.insertNodeInto(middle, root, 1); DefaultMutableTreeNode last = new DefaultMutableTreeNode("3"); model.insertNodeInto(last, root, 2); JTree tree = new Tree(model); TreeTestUtil.assertTreeUI(tree); tree.setSelectionPath(TreeUtil.getPathFromRoot(last)); TreeUtil.removeSelected(tree); assertSame(middle, tree.getSelectionPath().getLastPathComponent()); }