简体   繁体   中英

Netbeans GUI Builder: how to edit generated code

Im using Netbeans GUI Builder and I am adding a JTree to my form, as it does Netbeans is generating all the code for the JTree.

What i want to know is, is there a way in Netbeans to add code to the generated code... like in the source view in the Generated Code section it creates

jTree = new javax.swing.JTree();

i want to add populateJTree.addNodes(null, folder) so it looks like

jTree = new javax.swing.JTree(populateJTree.addNodes(null, folder));

Is there a way of doing this

i sorted it, if you go to the Properties window for the JTree and the Code section, you can add

new javax.swing.JTree(populateJTree.addNodes(null, folder));

to the custom creation code part and it will create

jTree = new javax.swing.JTree(populateJTree.addNodes(null, folder));

Yes there is a way to add code. Just right click on the component (in this example it would be JTree) than choose "Customize code", select "custom creation" and you are good to go.

  1. open .java file in notepad.
  2. now delete the lines above at initComponents() method,
    @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents and in the end of initComponents() method, remove // </editor-fold>//GEN-END:initComponents
  3. And in the end of your .java file the is a variable declaration it also contain generated code remove it also, // Variables declaration - do not modify//GEN-BEGIN:variables and // End of variables declaration//GEN-END:variables
  4. save the file from notepad.
  5. now open net-beans
  6. see now you can edit the Generated code.

    • if you want to get back your generated code to interact with design first save your file and then reverse the above process.*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM