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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10851468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 02:50:32  来源:igfitidea点击:

Netbeans GUI Builder: how to edit generated code

javauser-interfacenetbeansjtree

提问by newSpringer

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 Codesection 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

有没有办法做到这一点

回答by Paulius Matulionis

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),然后选择“自定义代码”,然后选择“自定义创建”即可。

回答by newSpringer

i sorted it, if you go to the Propertieswindow for the JTree and the Codesection, you can add

我把它排序了,如果你去PropertiesJTree 和Code部分的窗口,你可以添加

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

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));

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

回答by Govind Kaintura

  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:initComponentsand 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:variablesand // 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.*
  1. 在记事本中打开 .java 文件。
  2. 现在在 initComponents() 方法中删除上面的行,并在 initComponents() 方法
    @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents的末尾,删除 // </editor-fold>//GEN-END:initComponents
  3. 在 .java 文件的末尾是一个变量声明,它也包含生成的代码,也将其删除, // Variables declaration - do not modify//GEN-BEGIN:variables并且 // End of variables declaration//GEN-END:variables
  4. 从记事本保存文件。
  5. 现在打开网豆
  6. 现在您可以编辑生成的代码。

    • 如果您想取回生成的代码以与设计交互,请先保存您的文件,然后反转上述过程。*