File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to close a window without closing the whole application

 
Shamsa Aziz
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
Eclipse IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look the setDefaultCloseOperation of JFrame.


 
Nam Ha Minh
Ranch Hand
Posts: 502
Eclipse IDE Firefox Browser Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shamsa Aziz wrote:how to design an MDI in Jfram?


Use JInternalFrame
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic