File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Closing a JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Closing a JFrame" Watch "Closing a JFrame" New topic
Author

Closing a JFrame

Ryan Smith
Ranch Hand

Joined: Jun 29, 2004
Posts: 40
Alright, right now I feel completely dumb...all I want to do is create a MenuBar, which I've done, with a ActionListener attached to one of the menu items: a quit button. The actionEvent will be the closing of the JFrame, as I'm sure you've guessed.

After looking through all the API source files for JFrame's methods and inherited methods, I still can't find a method that will just close the window!!

Someone please kick me!
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

dispose()
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / JFC / AWT forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dmitry Melnik
Ranch Hand

Joined: Dec 18, 2003
Posts: 328
System.exit(...) will do it
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

dispose() if you want to get rid of the JFrame but keep the application alive. System.exit(0) if you want to exit the application loop altogether.

Just thought I would clarify the given solutions a bit.


GenRocket - Experts at Building Test Data
P. Sagdeo
Ranch Hand

Joined: Nov 13, 2003
Posts: 67
Dispose() - Destroys the JFrame completely, frees the resources.

System.exit(int) - Closes the entire program

JFrame.setVisible(false) - Makes the JFrame invisible, make it reappear with a setVisible(true)
[ July 19, 2004: Message edited by: P. Sagdeo ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Closing a JFrame