Search code examples
javajavafxopenjfx

Showing Stage/Dialog more than once in javafx application that is launched by Platform.startup()


I am building an application that is running in the background and provides access to a control panel (JavaFX Dialog) by clicking on the icon on the SystemTray.

JavaFX 9 adds the ability to launch JavaFX application without extending Application class, by invoking the method Platform.startup().

When the user double-clicks on the system tray icon, I call Platform.runLater() and pass to it the creation and showing of a new dialog. However, when the user closes the first dialog and try to open it again, it silently failed to open.

After investigating openJFX 11.0.1 source code, it turns out that JavaFX runtime terminates its toolkit once the last JavaFX window is closed.

I've tried to hide the dialog instead of closing it, but that didn't help either. Is there any workaround?


Solution

  • You want to use Platform.setImplicitExit(false).

    Sets the implicitExit attribute to the specified value. If this attribute is true, the JavaFX runtime will implicitly shutdown when the last window is closed; the JavaFX launcher will call the Application.stop() method and terminate the JavaFX application thread. If this attribute is false, the application will continue to run normally even after the last window is closed, until the application calls exit(). The default value is true.