• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jframe problem

 
Puneet N Vyas
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have designed a Gui containing main application which has a menu bar which contains a menu item which opens a new frame,now i need to close this frame,keeping the main application intact,i wrote system.exit() on the menu item of the new frame which closes not only this frame but also the main frame application,how can i close the new frame without closing the main application.

thanks for support
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fundupuneet vyas:
i have designed a Gui containing main application which has a menu bar which contains a menu item which opens a new frame,now i need to close this frame,keeping the main application intact,i wrote system.exit() on the menu item of the new frame which closes not only this frame but also the main frame application,how can i close the new frame without closing the main application.

thanks for support


Whenever you call System.exit method it will terminate the entire application.Keep this thing in mind
And for your query you can use setVisible method in JFrame class for that respective JFrame object.
[ April 28, 2008: Message edited by: Balasubramanian Chandrasekaran ]
 
Campbell Ritchie
Marshal
Posts: 52580
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know a lot about Swing threading, but you should call all your Swing operations from the Event Dispatch Thread. Find any Swing class in the API, then go through its description until you find the link to the threading policy, like here.

Now find out the default behaviour of a JFrame; Not certain, but I think it is HIDE_ON_CLOSE. Don't set up the default closing operation on your JFrame as EXIT_ON_CLOSE, but add a Window Listener which calls the JFrame's dispose() method when the window is closed (or closing).

And, as Balasubramanian Chandrasekaran has already told you, beware of System.exit().
 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You don't really NEED a WindowListener to do the job. You can use the WindowConstants.DISPOSE_ON_CLOSE for the new frame's default close operation.

Best regards,

- Aditya Jha
 
Guido Sautter
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be careful invoking dispose() in a WindowListener's windowClosing() method, this may result in an endless loop: invoking dispose() is one of the ways to make a window closing, thus invoking windowClosing() on any registered listeners ...

A way of catching this is to use

in the WindowListener, which will break the loop.
 
Campbell Ritchie
Marshal
Posts: 52580
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I forgot about DISPOSE_ON_CLOSE.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!