permaculture playing cards
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Closing a JFrame" Watch "Closing a JFrame" New topic

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

Dirk Schreckmann

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: 15302

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:
subject: Closing a JFrame
It's not a secret anymore!