• 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

Cancelling close in windowClosing

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is supposedly possible to cancel the closing of a window within the windowClosing() method. This is supposedly done by simply not closing it within the method, or that's what I'm understanding from the Java documentation. However, I have not found this to be the case at all.

The JOptionPane pops up just fine after I click the X, but the window closes regardless of whether I choose yes or no afterward. How do I properly go about preventing the window from closing?
[ April 26, 2004: Message edited by: Randy Anarcane ]
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add the following line to your code before the addWindowListener...

The default close operation when this is not specified is to dispose of the JFrame. So it doesn't matter what you do it's going to close unless you specify otherwise.
The windowClosing event is more or less a cleanup method so that you can tie up any loose ends before the window closes.
Also note that dispose() only kills the JFrame. It does not do the same thing as System.exit(0). I am sure you know that, but I wanted to make sure.
 
Randy Anarcane
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vielen Dank.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic