Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do something when my Javafx close?

Tags:

java

javafx

I want to call one function when my JavaFX program close. I have few classes which extends Stage. So i don't know in which stage my program will close.

So the first way to do this is to override close function in every stage i got and to call my function from there.

But i guess that there should be also other way. Is there any final function that is always called just before our program close ? So i can implement that function to put what i need to be done before program closes in there ?

like image 637
Miljan Rakita Avatar asked Oct 26 '25 20:10

Miljan Rakita


1 Answers

Override stop() in your Application subclass:

public class MyApp extends Application {

    @Override
    public void start(Stage primaryStage) {
        // startup code...
    }

    @Override
    public void stop() {
        // executed when the application shuts down
    }
}
like image 126
James_D Avatar answered Oct 29 '25 10:10

James_D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!