Reputation: 2678
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 ?
Upvotes: 5
Views: 10754
Reputation: 824
I just had the same problem and it turns out the solution was fairly simple.
Open your .form file in a text editer that is located in the src folder and change the first line from this:
Form="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"
to this:
Form="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"
Hope that helps someone!
Upvotes: 0
Reputation: 10045
BEFORE DOING THIS, close the file in Netbeans AND BACK UP the .java and the .form file you are about to edit.
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 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.
It should now be fixed for you.. I hope this helped a bit!
' Cheers!
Upvotes: 2
Reputation: 12339
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. :)
Upvotes: 0
Reputation: 142
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.
You can try the following (be sure to make a backup before):
setDefaultCloseOperation...
. getContentPane()
with this
pack();
at the last line.<Properties>
(and everything within) <SyntheticProperties>
. <Form ... type="...JPanelFormInfo">
into <Form ... type="...JFrameFormInfo">
As far as I observed, everything within the forms file can be deleted apart from the stuff within <Layout>
.
Good Luck.
Upvotes: 0
Reputation: 23629
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.
Upvotes: 0
Reputation: 10299
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).
Upvotes: 3
Reputation: 205775
You might look in Team > Local History
to see if you can revert.
Upvotes: 1
Reputation: 494
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...
Upvotes: 5