aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes GUI gives me two JFrames in Netbeans Desktop Application Template Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GUI gives me two JFrames in Netbeans Desktop Application Template" Watch "GUI gives me two JFrames in Netbeans Desktop Application Template" New topic
Author

GUI gives me two JFrames in Netbeans Desktop Application Template

Dave Elwood
Ranch Hand

Joined: Dec 27, 2002
Posts: 84
Using Netbeans I have been working with a GUI app for two years now. The code is generated at first from Netbeans IDE when selecting Java Desktop Application Project.

For the project Spacer it generates SpacerApp and SpacerView and it looks like this :


SpacerView looks more or less like this :


And now the punchline: I have found that I have another frame floating about here.

When I do this with the SpacerView class then two frames are visible.



Seems odd to me that this setup suggested by Netbeans offers one frame to use as the main guy (from FrameView) but
there is another frame (from app.getMainFrame()) floating around unused.
Why are there two? Is one of them a leftover from previous designs and should be avoided??
Can I use either one, or is one on its way to deprecation??
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
try this change, see what prints out


then uncomment the 2 lines and see if there's a difference in what's printed out.

if there are multiple frames, you might be better off posting in the Netbeans.org forum.

Dave Elwood
Ranch Hand

Joined: Dec 27, 2002
Posts: 84
Thanks for writing Michael, however what you have shown me doesn't really bring any light into the room.

This app the way it's written has two main frames, one accessible by getFrame() in the view class and the other accessible with app.getMainFrame().

I know that two frames will appear when I say app.getMainFrame().setVisible(true). The existance of these two frames is the heart of my question.

Question is, since this app.getMainFrame() JFrame object is totally useless, why does it exist at all? Would I be correct in doing this right off ? :





Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
just had a bit more of a read (Netbeans code is hard to follow) and, in theory,
JFrame mainFrame = app.getMainFrame();
and
app.getMainFrame().setBounds(10, 10, 500, 500);
should be the same frame, unless somewhere in throwing around the references there's a 'new JFrame()'

create another project and strip everything but frame-specific stuff, and your code to have 2 frames showing.
make sure we can compile/run/observe i.e. no org.jdesktop... references.

it should end up something similar to this (probably a few more classes)


and

if you run the above, there's only a single frame showing - at the secondary size/location
(swap them around, so the larger/centered specs are secondary, and this is what will be visible)
Dan Kempten
Greenhorn

Joined: Dec 26, 2008
Posts: 25


that's heartening to hear. I kept thinking, 'there must be an easier way, this is nuts.'

I'll try out your suggestions as soon as possible.

Thanks muchly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GUI gives me two JFrames in Netbeans Desktop Application Template