user2671610
user2671610

Reputation: 143

Splash screen does not work when self-contain the .jar

I use a splash screen feature for the javafx appliction. I use javafx ant task to run in order the fx:jar, fx:signjar, fx:deploy to produce the jar file, the jnlp file, the html file and the nativeBundles including "image" and "exe". The splash runs well when packaged in .jar file by double-clicks. However, when I double-click the exe file in the application image folder or the shortcut after the setup by running the .exe setup file, there is no splash screen. Why? The exe file does not run based on the jar file? Thanks for help.

Upvotes: 3

Views: 728

Answers (1)

brickonthewall
brickonthewall

Reputation: 195

I had the same problem and tried many possibilities in my fx:deploy (like adding a fx:jvmarg, fx:jvmuserarg and fx:splash under fx:info) and in my INNO script, I also tried generating the exe through javapackager and even changing the image format to png, jpg, bmp, but nothing makes the SplashScreen appears when it is running from a self-contained exe package. So I created my own alternative that may help whoever finds the same problem.

Main Class:

            SplashScr splash = new SplashScr ();
            splash.setVisible(true);
            MainFrame mainFrame = new MainFrame();

            SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
                @Override
                protected Void doInBackground() throws Exception {
                    Thread.sleep(2000);
                    return null;
                }

                protected void done() {
                    splash.setVisible(false);
                    mainFrame.setVisible(true);
                    splash.dispose();
                    mainFrame.startProcess(args);
                }
            };
            worker.execute();

Depending on how long your MainFrame takes to load, you can add more or less time in the Thread.sleep(2000) or even delete it, but it is important that this sleep is running inside a SwingWorker or else the splash may not appear.

SplashScr Class:

public class SplashScr extends JWindow {

  public SplashScr () {

    ImageIcon image = new ImageIcon(getClass().getResource("SplashScreen.png"));
    int width = image.getIconWidth();
    int height = image.getIconHeight();
    getContentPane().add(new JLabel("", image, SwingConstants.CENTER));
    setSize(width, height);
    setLocationRelativeTo(null);
  }
}

I hope it was useful for whoever found the same issue.

Upvotes: 2

Related Questions