简体   繁体   English

修改netbeans中的initComponents()

[英]modify initComponents() in netbeans

I modified some of the text fields in my GUI to use constructors which throw exceptions. 我在GUI中修改了一些文本字段,以使用引发异常的构造函数。 While the properties window of netbeans' swing designer allows me to modify the code of controls and containers, I can't see a way to modify the initComponents() method itself to throw exceptions so i would have to add try/catch blocks to many of my controls, which would be rather tedious. 虽然netbeans的swing设计器的属性窗口允许我修改控件和容器的代码,但是我看不到修改initComponents()方法本身以引发异常的方法,因此我必须向许多添加try / catch块我的控制,这将非常乏味。

Well you could try to do in a plain text editor. 好吧,您可以尝试在纯文本编辑器中进行操作。 But this would probably break your GUI editor. 但这可能会破坏您的GUI编辑器。 The other way around it is to have a standard constructor, ie public A(){} and public initialize(....) methods with proper arguments which can throw the exceptions and you would call them elsewhere, eg just after the initComponents() methods in your code. 解决该问题的另一种方法是拥有一个标准的构造函数,即带有适当参数的public A(){}和公共initialize(....)方法,这些方法会引发异常,您可以在其他地方调用它们,例如initComponents()方法。

But even better is to learn layout managers and hand-GUI-coding yourself so you will not need to rely on GUI builders. 但是更好的是自己学习布局管理器和手工进行GUI编码,这样您就不必依赖GUI构建器了。 This way you have full control over what is going on, and if your project is fairly complicated that is what you want. 这样,您就可以完全控制正在发生的事情,如果您的项目相当复杂,那就是您想要的。

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

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