• 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

Problem in Closing the window

 
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear friends,

Whenever i use Exit option from File Menu my application will prompt the user to save the file.

Whene i use ALT-F4 option also its doing the same.

But when i use the close button at the top right corner of the window and when i right click the application from the desktop taskbar and click Close, the application closes without asking the user to save the file.

Kindly provide your help.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
add a WindowListener, and in windowClosing() call your exit/save method

depending on what you are doing in your exit/save method, you may need to add
this to the constructor
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Michael,

Thanks for the reply.
Th logic given by you worked.
But some more probles are there.

Whenever i select Exit option from File Menu, the saveAs dialog appears, but if i click cancel my application should not exit. But it exits.

I also included JFrame.DO_NOTHING_ON_CLOSE as you suggested.

If i use windowListener, fileitemsaveas_actionPerformed method could not be called.

Kindly provide your reply.

This is the code i wrote:
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try these changes

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael.

This has solved my problem.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic