• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in Closing the window

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • 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.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
try these changes

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael.

This has solved my problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!