问题
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
回答1:
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));
回答2:
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.
回答3:
- open .java file in notepad.
- 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
- 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
- save the file from notepad.
- now open net-beans
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.*
来源:https://stackoverflow.com/questions/10851468/netbeans-gui-builder-how-to-edit-generated-code