import javax.swing.JTree;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreePath;
public class Main {
public static void main(String[] argv) throws Exception {
JTree tree = new JTree();
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
TreePath path = tree.getSelectionPath();
MutableTreeNode node = (MutableTreeNode) path.getLastPathComponent();
model.removeNodeFromParent(node);
model.setRoot(null);
}
}
|