This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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: 15299
    
    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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Closing a JFrame