This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 195977 - Dependency injection of main class in child components can bring down the Form Editor
Summary: Dependency injection of main class in child components can bring down the For...
Status: RESOLVED FIXED
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 6.x
Hardware: PC Windows 7
: P1 normal (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-25 02:53 UTC by konos5
Modified: 2011-03-16 22:46 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
a small working example in netbeans (24.03 KB, application/x-zip-compressed)
2011-03-11 03:21 UTC, konos5
Details

Note You need to log in before you can comment on or make changes to this bug.
Description konos5 2011-02-25 02:53:27 UTC
When starting a new Java Application and the main class extends a JFrame then the following problem will most likely occur; By placing a JPanel into the JFrame and then extending it thus creating a custom class, the form editor will collapse if and when we try to get a reference of the main class (that is the JFrame) by leaking the JFrame into the constructor of the JPanel.

Both the JFrame and the JPanel on it are created and manipulated from the GUI editor.
Comment 1 Antonin Nebuzelsky 2011-03-08 13:53:39 UTC
Can you please attach a sample project which demonstrates the problem with a list of reproducible steps what exactly needs to be done after the project is opened in NetBeans? Thanks.
Comment 2 konos5 2011-03-11 03:21:32 UTC
Created attachment 106898 [details]
a small working example in netbeans

Unfortunately I didn't manage to replicate the problem but this is exactly the "environment" that was causing it before in one of my previous projects.

What I experienced was the following:

1)Started netbeans
2)Opened up the project
3)Upon clicking on the design tab of the main class
the form editor would collapse giving out an error (can't remember exactly what)
4)If I commented out the custom code in the JPanel creation and "defaulted" the constructor in the JPanel code, everything was returned back to normal!

Please have a look at the code and don't hesitate to contact me for further information.

Thanks in advance!
Comment 3 konos5 2011-03-11 18:40:43 UTC
Pardon me in my previous post!

The problem is right there!
It just appears when you re-start netbeans!

Therefore, to see what I am talking about:

1)Load the "project" in netbeans
2)open my source files for editing and check the design tabs.
3)Now close and start netbeans again. If you try to go to the "design" tab,
netbeans will come with an error like that:

"error loading component....
...
error loading layout"..

Thanks again and my apologies for the previous vague post of mine...!
Comment 4 Tomas Pavek 2011-03-16 12:38:09 UTC
Now when having the example it's quite simple: the 'myPanel' class has no default constructor (with no parameters) so GUI builder is not able to create its instance included in the 'myFrame' form.

You probably put the panel to the frame when it still had the default constructor, then added the parameter later. Note that for design time the GUI builder is not able to interpret the instantiation code you specified, it always needs the default constructor, which is according to JavaBeans specification.

So it will work if you add e.g. the following to 'myPanel' class:
    public myPanel() {
        initComponents();
    }
Then close 'myFrame', recompile 'myPanel' (or for sure clean build the whole project), and open 'myFrame' again.
Comment 5 konos5 2011-03-16 22:46:19 UTC
That explains everything...!

I hope though that in a future version netbeans get some sort
of autosensing functionality (even though outside of the specs - it would help a lot)..! 

Thank you very much for your time!
Problem solved!