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 Android Security Essentials Live Lessons this week in the Android 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: 15299

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 ]
subject: Closing a JFrame
Similar Threads
Prevent JFrame from minimizing
One class calling another class incharge of GUI
extends JFrame or new JFrame()
how to restrict the focus between parent and child JFrame??
Multiple JFrames ?