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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Closing a JFrame" Watch "Closing a JFrame" New topic
Author

Closing a JFrame

Ben Wong
Greenhorn

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: 15292
    
    6

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


GenRocket - Experts at Building Test Data
Ben Wong
Greenhorn

Joined: Mar 27, 2006
Posts: 19
Thanks
Ben Wong
Greenhorn

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: http://aspose.com/file-tools
 
subject: Closing a JFrame
 
Similar Threads
partial display of JOptionPane
JFrame confusion
Calling JDialog from JDialog - Urgent please...
Cannot take populate JTextfield
How can I customised the Ok-Cancel Button in JOptionPane