I'm rethinking the design of my GUI. I designed a few JFrame with Netbeans automated GUI (yes, I'm lazy, and this generated code is often awful, I know !), but now I want them to be JPanel (actually, to inherit from another class that inherits JPanel). But I had the "setDefaultCloseOperation" modified, so my code is broken : setDefaultCloseOperation is impossible for a JPanel. Since I can't modify the generated code, I was wondering : is there a way to make Netbeans understand I changed my mind, and regenerate the code ?
我正在重新考虑我的GUI设计。我用Netbeans自动GUI设计了几个JFrame(是的,我很懒,这个生成的代码通常很糟糕,我知道!),但是现在我想让它们成为JPanel(实际上,从继承JPanel的另一个类继承)。但是,我修改了“setDefaultCloseOperation”,所以我的代码被破坏了:setDefaultCloseOperation对于一个JPanel来说是不可能的。由于我不能修改生成的代码,我想知道:有没有办法让Netbeans理解我改变了主意,重新生成代码?
8 个解决方案
#1
5
When I run into this (I've done the same thing before) I usually end up having to modify the generated code XML file (.form file) or just copying all of the controls I've added and paste into a new JPanel. Just my $0.02 but beware that this can break your code...
当我遇到这个(我以前也做过同样的事情)时,我通常不得不修改生成的代码XML文件(。或者只是复制我添加的所有控件并粘贴到一个新的JPanel中。只是我的0.02美元,但要小心这可能会破坏你的代码…
#2
3
IMHO, nb won't manage automatic refactoring in this case; it's easier to add new panel and copy-paste all elements from Your old JFrame (their methods will be copied as well).
在这种情况下,nb不会管理自动重构;添加新的面板和复制旧JFrame中的所有元素(它们的方法也会被复制)更容易。
#3
2
BEFORE DOING THIS, close the file in Netbeans AND BACK UP the .java and the .form file you are about to edit.
在执行此操作之前,请在Netbeans中关闭文件,并备份您将要编辑的.java和.form文件。
I just had this problem, and fixed it by changing the .form file, that follows with your .java file for the given type. In the top of this XML file you will see a:
我刚刚遇到了这个问题,并通过更改.form文件来修复它,该文件与您的.java文件对应的给定类型。在这个XML文件的顶部,您将看到:
<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
Just change this to:
只是改变这个:
<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
Notice that i just changed this part:
注意,我刚刚改变了这个部分:
type="org.netbeans.modules.form.forminfo.JPanelFormInfo"
After you have done this, reopen the file in netbeans, it will now tell you that there is an error, this is because you might have set some properties, that aren't available for a JPanel, but was for the JFrame. Just hit Edit, and then change one value in your GUI, this will force it to rebuild the generated code, and this way it will remove the properties that aren't applicable.
在您完成此操作之后,在netbeans中重新打开该文件,它将告诉您存在一个错误,这是因为您可能已经设置了一些属性,这些属性不是用于JPanel的,而是用于JFrame的。只需点击编辑,然后在GUI中更改一个值,这将迫使它重新生成生成的代码,这样它将删除不适用的属性。
It should now be fixed for you.. I hope this helped a bit!
现在应该为你准备好了。我希望这能有所帮助!
' Cheers!
“干杯!
#4
1
You might look in Team > Local History
to see if you can revert.
您可以查看一下>团队的本地历史,看看是否可以恢复。
#5
0
Can't you just remove the setDefaultCloseOperation() and any other calls to methods that are no longer in the super class? Making this call definitely doesn't make sense now that the class is not a JFrame.
您不能只删除setDefaultCloseOperation()和任何其他已不在超类中的方法的调用吗?如果这个类不是一个JFrame,那么这个调用肯定是没有意义的。
#6
0
I don't now what you broke, but I can tell you this: You can not tell Netbeans to change his own generated code the way you described it.
我现在不知道你怎么了,但我可以告诉你:你不能告诉Netbeans改变他自己生成的代码,就像你描述的那样。
You can try the following (be sure to make a backup before):
你可以试试下面的方法(一定要做一个备份):
- Open YourPanel.java in some editor
- YourPanel开放。java在一些编辑器
- Delete the line with
setDefaultCloseOperation...
. - 删除与setDefaultCloseOperation ....
- Replace all
getContentPane()
withthis
- 用这个替换所有的getContentPane()。
- Delete
pack();
at the last line. - 删除包();在最后一行。
- Open YourPanel.form in some editor
- YourPanel开放。形式在一些编辑器
- Delete the node
<Properties>
(and everything within) -
删除节点
(以及所有内部的内容) - Delete the node
<SyntheticProperties>
. - < SyntheticProperties >删除节点。
- In root node change from
<Form ... type="...JPanelFormInfo">
into<Form ... type="...JFrameFormInfo">
- 在根节点从 <表单…type = "……jpanelforminfo "> 到 <形式…类型=“…jframeforminfo ">
As far as I observed, everything within the forms file can be deleted apart from the stuff within <Layout>
.
在我观察到的情况下,表单文件中的所有内容都可以在 <布局> 中删除。
Good Luck.
祝你好运。
#7
0
Yes, you can simply copy and paste it to the JPanel. Make sure that, you JPanel size must greater or equal to the existing JFrame container size. :)
是的,你可以简单地复制粘贴到JPanel。确保您的JPanel大小必须大于或等于现有的JFrame容器大小。:)
#8
0
I just had the same problem and it turns out the solution was fairly simple.
我只是遇到了同样的问题,结果很简单。
- As others have said, make a backup of your file.
- 正如其他人所说,备份您的文件。
- Open your JFrame class and edit it to extend JPanel rather than JFrame.
- 打开JFrame类并编辑它以扩展JPanel而不是JFrame。
- Cut your main method method and put it into another class.
- 将你的主要方法方法剪切并放到另一个类中。
- Close your netbeans project and netbeans IDE
- 关闭netbeans项目和netbeans IDE。
-
Open your .form file in a text editer that is located in the src folder and change the first line from this:
在位于src文件夹中的文本编辑器中打开.form文件,并从该文件夹中更改第一行:
Form="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"
形式= " 1.5 " maxVersion = " 1.5 " type = " org.netbeans.modules.form.forminfo.JFrameFormInfo "
to this:
:
Form="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"
- After youve saved that. Open the netbeans project again.(it will open with an error)
- 你保存后。再次打开netbeans项目。(它会以一个错误打开)
- Modify one of the properties of the JPanel.
- 修改JPanel的一个属性。
- Run the programme. Netbeans will automatically get rid of all methods that are only associated with a JFrame. and it will run fine.
- 运行计划。Netbeans将自动删除与JFrame关联的所有方法。它会运行良好。
Hope that helps someone!
希望能帮助一些人!
#1
5
When I run into this (I've done the same thing before) I usually end up having to modify the generated code XML file (.form file) or just copying all of the controls I've added and paste into a new JPanel. Just my $0.02 but beware that this can break your code...
当我遇到这个(我以前也做过同样的事情)时,我通常不得不修改生成的代码XML文件(。或者只是复制我添加的所有控件并粘贴到一个新的JPanel中。只是我的0.02美元,但要小心这可能会破坏你的代码…
#2
3
IMHO, nb won't manage automatic refactoring in this case; it's easier to add new panel and copy-paste all elements from Your old JFrame (their methods will be copied as well).
在这种情况下,nb不会管理自动重构;添加新的面板和复制旧JFrame中的所有元素(它们的方法也会被复制)更容易。
#3
2
BEFORE DOING THIS, close the file in Netbeans AND BACK UP the .java and the .form file you are about to edit.
在执行此操作之前,请在Netbeans中关闭文件,并备份您将要编辑的.java和.form文件。
I just had this problem, and fixed it by changing the .form file, that follows with your .java file for the given type. In the top of this XML file you will see a:
我刚刚遇到了这个问题,并通过更改.form文件来修复它,该文件与您的.java文件对应的给定类型。在这个XML文件的顶部,您将看到:
<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
Just change this to:
只是改变这个:
<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
Notice that i just changed this part:
注意,我刚刚改变了这个部分:
type="org.netbeans.modules.form.forminfo.JPanelFormInfo"
After you have done this, reopen the file in netbeans, it will now tell you that there is an error, this is because you might have set some properties, that aren't available for a JPanel, but was for the JFrame. Just hit Edit, and then change one value in your GUI, this will force it to rebuild the generated code, and this way it will remove the properties that aren't applicable.
在您完成此操作之后,在netbeans中重新打开该文件,它将告诉您存在一个错误,这是因为您可能已经设置了一些属性,这些属性不是用于JPanel的,而是用于JFrame的。只需点击编辑,然后在GUI中更改一个值,这将迫使它重新生成生成的代码,这样它将删除不适用的属性。
It should now be fixed for you.. I hope this helped a bit!
现在应该为你准备好了。我希望这能有所帮助!
' Cheers!
“干杯!
#4
1
You might look in Team > Local History
to see if you can revert.
您可以查看一下>团队的本地历史,看看是否可以恢复。
#5
0
Can't you just remove the setDefaultCloseOperation() and any other calls to methods that are no longer in the super class? Making this call definitely doesn't make sense now that the class is not a JFrame.
您不能只删除setDefaultCloseOperation()和任何其他已不在超类中的方法的调用吗?如果这个类不是一个JFrame,那么这个调用肯定是没有意义的。
#6
0
I don't now what you broke, but I can tell you this: You can not tell Netbeans to change his own generated code the way you described it.
我现在不知道你怎么了,但我可以告诉你:你不能告诉Netbeans改变他自己生成的代码,就像你描述的那样。
You can try the following (be sure to make a backup before):
你可以试试下面的方法(一定要做一个备份):
- Open YourPanel.java in some editor
- YourPanel开放。java在一些编辑器
- Delete the line with
setDefaultCloseOperation...
. - 删除与setDefaultCloseOperation ....
- Replace all
getContentPane()
withthis
- 用这个替换所有的getContentPane()。
- Delete
pack();
at the last line. - 删除包();在最后一行。
- Open YourPanel.form in some editor
- YourPanel开放。形式在一些编辑器
- Delete the node
<Properties>
(and everything within) -
删除节点
(以及所有内部的内容) - Delete the node
<SyntheticProperties>
. - < SyntheticProperties >删除节点。
- In root node change from
<Form ... type="...JPanelFormInfo">
into<Form ... type="...JFrameFormInfo">
- 在根节点从 <表单…type = "……jpanelforminfo "> 到 <形式…类型=“…jframeforminfo ">
As far as I observed, everything within the forms file can be deleted apart from the stuff within <Layout>
.
在我观察到的情况下,表单文件中的所有内容都可以在 <布局> 中删除。
Good Luck.
祝你好运。
#7
0
Yes, you can simply copy and paste it to the JPanel. Make sure that, you JPanel size must greater or equal to the existing JFrame container size. :)
是的,你可以简单地复制粘贴到JPanel。确保您的JPanel大小必须大于或等于现有的JFrame容器大小。:)
#8
0
I just had the same problem and it turns out the solution was fairly simple.
我只是遇到了同样的问题,结果很简单。
- As others have said, make a backup of your file.
- 正如其他人所说,备份您的文件。
- Open your JFrame class and edit it to extend JPanel rather than JFrame.
- 打开JFrame类并编辑它以扩展JPanel而不是JFrame。
- Cut your main method method and put it into another class.
- 将你的主要方法方法剪切并放到另一个类中。
- Close your netbeans project and netbeans IDE
- 关闭netbeans项目和netbeans IDE。
-
Open your .form file in a text editer that is located in the src folder and change the first line from this:
在位于src文件夹中的文本编辑器中打开.form文件,并从该文件夹中更改第一行:
Form="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"
形式= " 1.5 " maxVersion = " 1.5 " type = " org.netbeans.modules.form.forminfo.JFrameFormInfo "
to this:
:
Form="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"
- After youve saved that. Open the netbeans project again.(it will open with an error)
- 你保存后。再次打开netbeans项目。(它会以一个错误打开)
- Modify one of the properties of the JPanel.
- 修改JPanel的一个属性。
- Run the programme. Netbeans will automatically get rid of all methods that are only associated with a JFrame. and it will run fine.
- 运行计划。Netbeans将自动删除与JFrame关联的所有方法。它会运行良好。
Hope that helps someone!
希望能帮助一些人!