• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Cancel a windowClosing()  RSS feed

 
Amit Agarwal
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
is it possible to cancel/avoid the closing of a JFrame if the user clicks on the cross(x) on the top right of the frame in a java Application.
i want to give a message to the user:
Save Changes to the document?
with the options:
Yes / No / Cancel
i can do the programming of Yes/No in the windowClosing() of the WindowListener associated with the JFrame. but, i am unable to give a functionality for the Cancel.
Your help will be greatly appreciated.
---------
Amit
 
Sanjay Bahrani
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi There,
What are you using for the Yes/No/Cancel Option, Are you using the JOptionPane......
 
Amit Agarwal
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sanjay,
Yes I am using JOptionPane.showConfirmDialog()
---------
Amit
 
Ashwin Desai
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit,
You can use frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE ); to achieve that behaviour.
Ashwin.
 
Amit Agarwal
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Ashwin
------
Amit
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!