This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Close one Frame open another? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Close one Frame open another?" Watch "Close one Frame open another?" New topic
Author

Close one Frame open another?

Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 171
Hi folks,
I have a JFrame with a button. When the button is pressed I want to close the current frame and open a new one.
I find that dispose() and System.exit(0) kill both frames! Any ideas?
regards
Simon Ingram
Jeremy Tartaglia
Ranch Hand

Joined: Mar 11, 2004
Posts: 62
System.exit(0) stops ALL processes, including the new frame, so that's a bad idea. Just use dispose() after you create the new JFrame, and you should be fine. You may also need to change the default close operation (I think by setDefaultCloseOperation(JFrame.DEFAULT_NO_CLOSE) or something similar to that), so if just using dispose() doesn't work, check the documentation for that.
[ March 11, 2004: Message edited by: Jeremy Tartaglia ]
Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 171
Thanks, Jeremy
the dispose on its own does the trick! I did not need to setDefaultCloseOperation.
Thanks once again
Simon
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Close one Frame open another?
 
Similar Threads
How i close my frame when i click in the button???
NetBeans IDE 5.5
For set focus on frame..
For set focus on frame..
Help for JFrame