Java Edit JTree Node

How To Update Selected Node From JTree Using Java NetBeans

edit jtree node in java



In this Java Tutorial we will see How To Edit The Selected JTree Node With Value From JTextField Using DefaultMutableTreeNode On Button Click Event In Java NetBeans .




Project Source Code:

private void jButtonEditActionPerformed(java.awt.event.ActionEvent evt) {                                            
        
        // get selected node
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        
        selectedNode.setUserObject(jTextField1.getText());
        
        DefaultTreeModel model = (DefaultTreeModel) jTree1.getModel();
        
        model.reload();
    } 


OutPut:

java update jtree selected node




Share this

Related Posts

Previous
Next Post »