简体   繁体   English

Netbeans GUI Builder:如何编辑生成的代码

[英]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. 我正在使用Netbeans GUI Builder,并且正在向表单中添加JTree,因为Netbeans会为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 我想知道的是,Netbeans中是否有一种方法可以将代码添加到生成的代码中...就像在它创建的“ Generated Code部分的源代码视图中一样

jTree = new javax.swing.JTree();

i want to add populateJTree.addNodes(null, folder) so it looks like 我想添加populateJTree.addNodes(null, folder)所以它看起来像

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 我对它进行了排序,如果转到“ JTree”和“ Code部分的Code Properties窗口,则可以添加

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. 只需右键单击该组件(在此示例中为JTree),然后选择“定制代码”,选择“定制创建”即可。

  1. open .java file in notepad. 在记事本中打开.java文件。
  2. now delete the lines above at initComponents() method, 现在在initComponents()方法中删除上面的行,
    @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 @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents ,在initComponents()方法的最后,删除// </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 在.java文件的末尾是一个变量声明,它还包含生成的代码,也将其删除, // Variables declaration - do not modify//GEN-BEGIN:variables// 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.* 如果您想找回生成的代码与设计进行交互,请先保存文件,然后逆转上述过程。*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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