Java Splash Screen - Advanced Installer Community
swhite
Posts: 3
Joined: Tue Apr 24, 2018 1:17 pm

Java Splash Screen

I'm building an installer for a Java (GUI) application, and have recently added a splash screen to the application. However, when I try to configure Advanced Installer to use the splash screen it doesn't work as expected. Specifically, the splash screen appears but does not disappear when the application starts. In the Java Products page I have tried both with 'Use native Java 6 splash screen' and without, and get the same end result in both cases.

My code has provision to take down the splash screen once the application has started, so, outside of Advanced Installer,
java -splash:Splash.jpg -jar MyApp.jar
works as expected.

I just upgraded to version 14.8 in case it was an issue that has since been fixed.
Can you help? Any ideas?

Thanks in advance
swhite
Posts: 3
Joined: Tue Apr 24, 2018 1:17 pm

Re: Java Splash Screen

I think I've managed to answer my own question. In response to another question you say:
The splash screen is displayed until the application has started (the "main" function of your java application is executed completely). Therefore you can show it for a longer time by modifying your application, that is by delaying the return from your "main" function.
My main method in the Java code calls Application.launch() and in the JavaDoc for Application.launch(), it says:
Launch a standalone application. This method is typically called from the main method(). It must not be called more than once or an exception will be thrown.
The launch method does not return until the application has exited, either via a call to Platform.exit or all of the application windows have been closed.
These two pieces of information together would mean that I cannot call Application.launch() in my main method if I want the splash screen to close(?)
swhite
Posts: 3
Joined: Tue Apr 24, 2018 1:17 pm

Re: Java Splash Screen

Just to say this is an issue that, I imagine, affects only JavaFX applications - because of the launch method - and I found that I could solve it by calling the launch method from a separate thread, but delaying the return from the main method until the application has launched.
FYI, here is a skeleton of my solution:

Code: Select all

public class MyApp extends Application {

    private static CountDownLatch startupLatch;
    
    ...
    
    public void start(Stage stage) throws Exception {
        ...
        final SplashScreen splash = SplashScreen.getSplashScreen();
        if (splash != null) {
            splash.close();
        }
        
        stage.show();
        startupLatch.countDown();
    }
    
    ...
    
    public static void main(String[] args) throws Exception {
        startupLatch = new CountDownLatch(1);
        Runnable runnable = () -> {
            launch(args);
        };
        Thread thread = new Thread(runnable);
        thread.start();
        startupLatch.await();
    }
}
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Java Splash Screen

Hello and welcome to our forums,

I'm glad you got a working solution. Thank you for sharing it with us. I'm sure it will be valuable for future users facing the same limitations.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”