Lompat ke konten Lompat ke sidebar Lompat ke footer

Java Delete JTree Node

How To Remove Selected Node From A JTree Using Java NetBeans

 How To Remove Selected Node From A JTree Using Java NetBeans Java Delete JTree Node



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);
    } 


OutPut:

 How To Remove Selected Node From A JTree Using Java NetBeans Java Delete JTree Node




Posting Komentar untuk "Java Delete JTree Node"