Netbeans GUI Builder: how to edit generated code

给你一囗甜甜゛ 提交于 2019-12-23 05:29:09

问题


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:


  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.*


来源:https://stackoverflow.com/questions/10851468/netbeans-gui-builder-how-to-edit-generated-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!