I want my JavaFX program to clean up the program when I press the x button in the top right corner of the window. How can I do that? The cleanup code is
JIntellitype.getInstance().cleanUp();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you have multiple windows and the cleanup is just for resources allocated to the window being closed, add an appropriate eventhandler for the window’s setOnHidden event.
A description of the Window.setOnHidden event:
If you create multiple Stages for your JavaFX Application, the Application will close when the last Stage for the Application closes. When the Application closes, then the Application’s stop method is called, which you can implement by overriding it in your Application class.
A description of the Application.stop method:
In your case, providing a implementation of Application.stop is probably the most appropriate solution.