We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

handing window closing envent question.

khacduyst
khacduyst asked
on
Medium Priority
310 Views
Last Modified: 2010-03-31
i want before window is close by user (click on window x button), my application ask and give user a last change by show yes no dialog ,if yes do close window if no, rollback (do nothing, window still visible) i listening on windowClosing event but i don't know how to rollback, here my code


        f.addWindowListener(new WindowAdapter() {
                                public void windowClosing(WindowEvent e) {
                                    if(showQuestionDialog("Would you like shutdown application?","Confirm message")==true){
                                        System.exit(0);                                                        
                                    }else{
                                        f.setVisible(true);                                        
                                    }
                                }
                            }
        );


f is my JFrame. whatever user choose yes or no, window still close, please help me
Comment
Watch Question

Author

Commented:
showQuesionDialog() function return true if yes and false for another option
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
set the default close operation of your fema eto do nothing

f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

do this when you create frame

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
thanks for very quick reply : )
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
no worries :)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.