java Netbeans 代码生成问题:如何编辑自动生成的代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7284960/
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-30 19:24:58  来源:igfitidea点击:

Netbeans code-gen woes: How to edit auto generated code?

javanetbeanscode-generation

提问by Jay

Ok. So here's a netbeans issue thanks to auto generated code from GUI designer. I designed a GUI using netbeans UI designer and it was compiled for java 1.6. After I finished my UI, I realized that I was supposed to do this for Java 1.4 and not 1.6. In the effort to downgrade from 1.6 to 1.4, I altered the form properties to use Swing Extensions Library and I got rid of enhanced forloop and generics in my code and I am stuck with this final error:

行。因此,由于 GUI 设计器自动生成的代码,这是一个 netbeans 问题。我使用 netbeans UI 设计器设计了一个 GUI,它是为 java 1.6 编译的。完成 UI 后,我意识到我应该为 Java 1.4 而不是 1.6 执行此操作。在从 1.6 降级到 1.4 的过程中,我更改了表单属性以使用 Swing 扩展库,并且在我的代码中去掉了增强的 forloop 和泛型,我遇到了这个最终错误:

Error method getString in class org.jdesktop.application.ResourceMap cannot be applied to given types; required: java.lang.String,java.lang.Object[] found: java.lang.String reason: actual and formal argument lists differ in length

类 org.jdesktop.application.ResourceMap 中的错误方法 getString 无法应用于给定类型;要求:java.lang.String,java.lang.Object[] 找到:java.lang.String 原因:实际和形式参数列表的长度不同

This comes from the code block that was auto-generated by Netbeans, for this method call:

这来自 Netbeans 自动生成的代码块,用于此方法调用:

resourceMap.getString("panel.tabTitle");

Obviously, this probably could be resolved by writing this:

显然,这可能可以通过编写以下内容来解决:

resourceMap.getString("panel.tabTitle",new Object{String.class});

I am, however, stumped on how I would make netbeans do this change to the code it generated! Let me know if you have seen this issue before and were able to resolve it. Appreciate your help.

然而,我对如何让 netbeans 对它生成的代码进行这种更改感到困惑!如果您以前见过这个问题并且能够解决它,请告诉我。感谢你的帮助。

回答by Jayanga Kaushalya

If you just want to edit codes. Open code with another editor just like notepad or something. And if you remove GEN-BEGIN:initComponentsjust before the auto generated code you can edit code through netbeans also.

如果您只想编辑代码。用另一个编辑器打开代码,就像记事本之类的。如果您GEN-BEGIN:initComponents在自动生成的代码之前删除,您也可以通过 netbeans 编辑代码。

回答by Jay

Alright. I've been able to resolve this without editing the code. However, I figured I would award kjaushalya for his answer coz the question sounded more like 'how do I edit netbeans gen-code' as opposed to 'how do I handle resource mapping with netbeans'.

好吧。我已经能够在不编辑代码的情况下解决这个问题。但是,我想我会奖励 kjaushalya 的回答,因为这个问题听起来更像是“我如何编辑 netbeans gen-code”而不是“我如何使用 netbeans 处理资源映射”。

Anyway, I edited the netbeans form to turn off resource mapping and that removed all the auto generated code.

无论如何,我编辑了 netbeans 表单以关闭资源映射并删除了所有自动生成的代码。