aspose 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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Closing a JFrame" Watch "Closing a JFrame" New topic

Closing a JFrame

Ben Wong

Joined: Mar 27, 2006
Posts: 19
I have one main JFrame for my program which creates another JFrame, like a JOptionPane. However, I chose not to use a JOptionPane because the new Jframe contains a form in which the user enters some data.

My question is: how do I close this second JFrame when the user clicks the "OK" button? Is it possible without using a JOptionPane?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286

On your second JFrame OK button's event handler, just call dispose().

GenRocket - A Test Data Generation Platform
Ben Wong

Joined: Mar 27, 2006
Posts: 19
Ben Wong

Joined: Mar 27, 2006
Posts: 19
The problem is that my first class instantiates the JFrame for the second class. The second class extends JPanel and therefore cannot see the dispose() method.

The solution I have so far is to have the second class nested in the first.
I agree. Here's the link:
subject: Closing a JFrame
Similar Threads
partial display of JOptionPane
JFrame confusion
How can I customised the Ok-Cancel Button in JOptionPane
Cannot take populate JTextfield
Calling JDialog from JDialog - Urgent please...