这是我的删除节点的方法
但是删除后节点还存在
当在点击树的时候被删除的节点与树的连线没了。
但节点还是能看到就像下面一样
删除前
aaaa
   |__bb
       |__cc
删除后
aaaa
   |__bb
       __cc
private void cutNode(){
                  //nodeSelected是被选中的节点
DefaultMutableTreeNode nodeSelected = getTreeNode(getTreePath()) //model.removeFromParent(nodeSelected );
nodeSelected.removeFromParent();
jTree.repaint();


}

解决方案 »

  1.   

    private void cutNode(){
                      //nodeSelected是被选中的节点
    DefaultMutableTreeNode nodeSelected = getTreeNode(getTreePath()) //model.removeFromParent(nodeSelected );
                      nodeSelected.removeAllChildren();/// add this.
    nodeSelected.removeFromParent();
    jTree.repaint();
    }
    reason: see java api
     void removeAllChildren() 
              Removes all of this node's children, setting their parents to null. 
     void removeFromParent() 
              Removes the subtree rooted at this node from the tree, giving this node a null parent.