aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to close a window without closing the whole application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to close a window without closing the whole application" Watch "How to close a window without closing the whole application" New topic
Author

How to close a window without closing the whole application

Shamsa Aziz
Greenhorn

Joined: Dec 06, 2012
Posts: 11
Salaam all!

hi everyone, how to design an MDI in Jfram? I am having a problem that when I close a window the main application closes.
I have designed a jframe having three jbuttons so I want to achieve a functionality that when I will click a button a new fram should be opened on that existing one and when I will close it ( whether by clicking the close jButton or [X] on the fram) that window should be closed not the whole app.

how to do that???
Bruno Candido Volpato da Cunha
Greenhorn

Joined: Feb 21, 2012
Posts: 18

Look the setDefaultCloseOperation of JFrame.



Bruno Candido Volpato da Cunha
Oracle Certified Java Programmer 6
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

Shamsa Aziz wrote:how to design an MDI in Jfram?


Use JInternalFrame


PM Me If You Want to get Urgent Help on Java Programming
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2316
    
  49
When you click on a button and show a new window you should probably be using a JDialog and not a JFrame. If you want to stop the user accessing the JFrame whilst the JDialog is displayed you can can make the JDialog modal.

If you really want to implement an MDI (for example like a text editor) then add a JDesktopPane to your JFrame and add JInternalFrames to it. See - http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html
Shamsa Aziz
Greenhorn

Joined: Dec 06, 2012
Posts: 11
Bruno Candido Volpato da Cunha wrote:Look the setDefaultCloseOperation of JFrame.





thanks a lot but It is for the close option[X] on the window I guess . How to do the same for the jButton close?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
from the link you've already clicked on, scroll back up the page to the methods summary,
in particular methods inherited from window (there you'll find a method starting with 'd').

I agree with earlier posts - a second JFrame is extremely rare, except in a bad program.
as well as JDialog, JInternalFrame, you could even have your frame set as a CardLayout,
which gives you the option of switching between pages.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to close a window without closing the whole application