• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Closing a JFrame

 
Ben Wong
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On your second JFrame OK button's event handler, just call dispose().
 
Ben Wong
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Ben Wong
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic