Java Delete JTree Node
How To Remove Selected Node From A JTree Using Java NetBeans
In this Java Tutorial we will see How To Delete The Selected JTree Node Using DefaultMutableTreeNode + DefaultTreeModel On Button Click Event In Java NetBeans .
Project Source Code:
private void jButtonRemoveNodeActionPerformed(java.awt.event.ActionEvent evt) {
// get selected node
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
DefaultTreeModel model = (DefaultTreeModel) jTree1.getModel();
if(selectedNode != jTree1.getModel().getRoot())
model.removeNodeFromParent(selectedNode);
else
model.setRoot(null);
}
Posting Komentar untuk "Java Delete JTree Node"