Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java SplashScreen in Java Web Start

I am trying to move my Java Swing project to Java Web Start and I have problem with the splash screen. This application uses Maven.

When I load my application via the command-line or by an external exe, it displays the splash screen correctly.

final SplashScreen splash = SplashScreen.getSplashScreen();

When I run application via Java Web Start, it always return null.

Yes, I know about splash screen section in JNLP file.

<icon kind="splash" href="splash.png"/>

But this will show splash screen before the application is loaded and not when the application is running. In other words, it isn't a replacement for the --splash switch.

In the manifest file, I have:

   SplashScreen-Image: (URL to resource,  file in jar)

This works well only when I run jar file and not in Java Web Start.

Has anybody had this same problem and found any solution for this? I need a splash screen because the application takes several seconds to start and nothing is displayed for user in this time.

like image 754
Krystek Avatar asked Mar 14 '26 07:03

Krystek


1 Answers

To show a splash screen for JNLP clients, call the start() method passing the splash image path. To remove the splash screen, call the stop() method.

public class ShowSplash 
{
   private static JWindow splashFrame;

   public void start(String splashImagePath) throws Exception
   {
      JLabel label;
      ImageIcon image;
      URL url;

      splashFrame = new JWindow();
      url         = ShowSplash.class.getResource(splashImagePath);
      image       = new ImageIcon(url);
      label       = new JLabel(image);

      splashFrame.add(label, BorderLayout.CENTER);
      splashFrame.pack();
      splashFrame.setLocationRelativeTo(null);
      splashFrame.setVisible(true);
   }

   public void stop() throws Exception
   {
      splashFrame.dispose();

      splashFrame = null;
   }
}
like image 87
mikemil Avatar answered Mar 16 '26 20:03

mikemil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!