我正在尝试将Java Swing项目移至Java Web Start 我的启动画面有问题。此应用程序使用Maven。
当我通过命令行或外部exe加载我的应用程序时, 它正确显示启动画面。
final SplashScreen splash = SplashScreen.getSplashScreen();
当我通过Java Web Start运行应用程序时,它总是返回null
。
是的,我知道JNLP文件中的启动画面部分。
<icon kind="splash" href="splash.png"/>
但是这会在加载应用程序之前显示启动画面而不是
当应用程序运行时。换句话说,它不是--splash
开关的替代品。
在清单文件中,我有:
SplashScreen-Image: (URL to resource, file in jar)
只有当我运行jar文件而不是Java Web Start时才能正常工作。
有没有人遇到同样的问题并找到了解决方案? 我需要一个启动画面,因为应用程序需要几秒钟才能启动,此时没有为用户显示任何内容。
答案 0 :(得分:2)
要显示JNLP客户端的启动画面,请调用传递启动图像路径的start()
方法。要删除初始屏幕,请调用stop()
方法。
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;
}
}
答案 1 :(得分:1)
基于JWS的启动画面对基于AWT的SplashScreen
使用完全不同的功能(以及不同的加载原理)。 JWS splash始终是JNLP文件中引用的松散文件。我们无法访问JNLP上的绘图。
答案 2 :(得分:0)
感谢您的回答,但我在使用JWindow替换SplashRenderer时遇到了问题。
这是代码:
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);
如果我设置了setAlwyasOnTop或者我设置了这个方法,那么Window总是在后面,没有metter 在后台线程。在这种情况下,SplashRender始终保持最佳状态,但JWindow不会。
目前效果是 - 当我启动APP时,启动时窗口不可见,但是当MainFrame出现时会显示。