To add an element dynamically , we will use three different classes.

Design Diagram for Tree:-



 public class TreeViewExample extends javax.swing.JFrame {

    /**
     * Creates new form TreeViewExample
     */
    DefaultTreeModel model;
    public TreeViewExample() {
        initComponents();
        model = (DefaultTreeModel) jTree1.getModel();
    }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) jTree1.getModel().getRoot();
        DefaultMutableTreeNode child = new DefaultMutableTreeNode(jTextField1.getText());
        model.insertNodeInto(child, root, root.getChildCount());
    }  

}



Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post