• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

close the parent widow when user selects YES_OPTION from JOptionPane

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
setVisible(false) and dispose() dit it. Sorry to bother.

Thanks any way...

Anu
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You guys haven't done this much, have ya? I suggest you study this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic