Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

close the parent widow when user selects YES_OPTION from JOptionPane  RSS feed

 
Anu Bhagat
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have implemented a JOptionPane confirm dialog with YES NO option with the code below
int result = JOptionPane.showConfirmDialog((Component) null,
"Do you really want to quit?",
"alert", JOptionPane.YES_NO_OPTION);

I can get the user response with the code below
if (result == JOptionPane.YES_OPTION) {
System.out.println(" you selected YES option");}

I want to close the parent window when user selects YES_OPTION.

How can I do this?

Thanks in advance.

Anu

 
Anu Bhagat
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setVisible(false) and dispose() dit it. Sorry to bother.

Thanks any way...

Anu
 
Rob Spoor
Sheriff
Posts: 20895
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dispose() alone is sufficient. And that's a good practice, to always dispose() your windows. If you don't, the window will keep the Event Dispatcher Thread alive and your application will never properly exit unless you call System.exit(X). This is problematic since JFrame and JDialog both have HIDE_ON_CLOSE as the default close operation. Just last month I had to fix this at work because someone less known with Swing* didn't know about this. It would have been better if DISPOSE_ON_CLOSE were the default; if people really don't need the window to be disposed they can always change it.

We usually build web applications.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!