Reputation: 31
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.
Upvotes: 3
Views: 1461
Reputation: 1241
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;
}
}
Upvotes: 2
Reputation: 31
Thanks for answers, but I have problem with replace SplashRenderer with JWindow.
Here is code:
splashFrame = new JWindow();
splashFrame.setBackground(Color.white);
JPanel splashPanel = new JPanel();
splashPanel.setLayout(new BorderLayout());
JLabel image = new JLabel(img);
splashPanel.add(image);
splashFrame.setContentPane(splashPanel);
splashFrame.pack();
splashFrame.setLocationRelativeTo(null);
splashFrame.setAlwaysOnTop(true);
splashPanel.paintImmediately(0, 0, splashPanel.getSize().width, splashPanel.getSize().height);
splashFrame.setSize(splashPanel.getSize().width,splashPanel.getSize().height);
splashFrame.setLocation(100, 100);
splashFrame.setVisible(true);
The Window is always in back, no metter if I set setAlwyasOnTop or if I set this methods in background thread. SplashRender in this case always stays on top, but JWindow not.
Currently effect is - When I start APP the Window is not visible during start up, but it's shows when MainFrame appear.
Upvotes: 0
Reputation: 168825
The JWS based splash screen uses totally different functionality (and a different loading philosophy) to the AWT based SplashScreen
. The JWS splash is always a loose file that is referenced in the JNLP file. We cannot get access to draw on the JNLP splash.
Upvotes: 1