After starting the JavaFX toolkit by default, it closes when the last visible window closes.
To prevent this, you can call
Platform.setImplicitExit(false);
You usually do this in your start(...) method, although it can be called from any thread.
To exit the application, you will need to call
Platform.exit();
(since the application no longer automatically exits).
source share