【问题标题】:Java SplashScreen in Java Web StartJava Web Start 中的 Java SplashScreen
【发布时间】:2014-02-14 23:46:53
【问题描述】:

我正在尝试将我的 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 中运行时才有效。

有没有人遇到过同样的问题并找到任何解决方案? 我需要一个启动画面,因为应用程序需要几秒钟才能启动,并且此时没有为用户显示任何内容。

【问题讨论】:

    标签: java swing maven jnlp splash-screen


    【解决方案1】:

    要为 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;
       }
    }
    

    【讨论】:

      【解决方案2】:

      基于 JWS 的初始屏幕使用与基于 AWT 的SplashScreen 完全不同的功能(和不同的加载原理)。 JWS 飞溅始终是在 JNLP 文件中引用的松散文件。我们无法访问 JNLP 启动画面。

      【讨论】:

      • 是的,但我认为在 Java Web Start 中存在任何替代 --splash 开关或清单条目 SplashScreen-Image。
      【解决方案3】:

      感谢您的回答,但我在用 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 还是设置这个方法 在后台线程中。在这种情况下,SplashRender 始终保持在顶部,但 JWindow 不会。

      目前的效果是——当我启动APP时,窗口在启动过程中是不可见的,但在MainFrame出现时显示。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多