Search code examples
javajavafxsplash-screen

Image as splashscreen for JavaFX application not hiding automatically


I have a simple .png image file that I wish to show while the JavaFX application is loading.

I am using NetBeans as my IDE and I know that splashscreen can be added like so: Project properties -> Run -> VM Options: -splash:path-to-image

Now the splashscreen starts nicely, but it won't close after my application has started. Just sits there on the screen until I close my application completely. As the documentation says (http://docs.oracle.com/javase/7/docs/api/java/awt/SplashScreen.html) "The splash screen window is closed automatically as soon as the first window is displayed by Swing/AWT". JavaFX is not Swing nor AWT application. So how can I close it?

Any help is appreciated!


Solution

  • Ok, answering my own question.

    When splash is set in VM Options: -splash:path-to-image. The in JavaFX I was able to close it like this:

    //Get the splashscreen
    final SplashScreen splash = SplashScreen.getSplashScreen();
    
    //Close splashscreen
        if (splash != null) {
            System.out.println("Closing splashscreen...");
            splash.close();
        }
    

    Hope this is somewhat helpful to others also! ;)