سؤال

Our maven/Netbeans platform application uses a custom image on startup, by replacing

Nbm-branding > core.jar > org.netbeans.core.startup > splash.gif

I tried making it an animated .gif, but only the first frame is displayed.

How would one possibly go about implementing an animated splash screen, maybe by running some JavaFX window animations?

I've seen another other SO question, but it wasn't really answered - please notice I'm asking about how to integrate a custom splash screen with my Netbeans Platform application, and not how to actually build it.

هل كانت مفيدة؟

المحلول

Surprisingly enough, I found out how to plug in a custom splash screen based on this post about user authentication and authorization.

Basically, one needs to write another start-up class, instead of the platform's default:

import java.lang.reflect.Method;

public class CustomStartup {

    private static final String NB_MAIN_CLASS = "org.netbeans.core.startup.Main";

    public static void main(String[] args) throws Exception {
        // do whatever you need here (e.g. show a custom login form)
        System.out.println("Hello world! I am a custom startup class");
        JWindow splash = initSplash();

        // once you're done with that, hand control back to NetBeans
        ClassLoader classloader = Thread.currentThread().getContextClassLoader();
        Class<?> mainClass = Class.forName(NB_MAIN_CLASS, true, classloader);

        Object mainObject = mainClass.newInstance();
        Method mainMethod = mainClass.getDeclaredMethod("main", new Class[]{String[].class});
        mainMethod.invoke(mainObject, (Object) args);

        splash.setVisible(false);
    }
}

In that class, one can create a JavaFX stage, embed it into a JWindow, and show it:

public JWindow initSplash(){
       JWindow window = new JWindow();
       final JFXPanel fxPanel = new JFXPanel();
       window.add(fxPanel);
       window.setVisible(true);
       window.setLocationRelativeTo(null);

        Platform.runLater(new Runnable() {

            @Override
            public void run() {
                Scene scene = new Scene(new CustomFxSplash(), 475, 300, true);
                fxPanel.setScene(scene);
            }
        }
       return window;
}

Other things to remember are:

  • Suppress the original NetBeans splash screen by running your app with the --nosplash parameter.

  • Call your custom initialization class by running your app with the -J-Dnetbeans.mainclass=com.package.splash.CustomStartup parameter

  • As the link suggests this custom class has to be on the platform's initialization classpath, meaning inside the platform/core folder.

نصائح أخرى

The current version of the NetBeans class that is responsible for rendering the splash screen can be viewed online here: org.netbeans.core.startup.

The culprit code that prevents the gif from animating is this line (line 546)

graphics.drawImage(image, 0, 0, null);

In order for the gif to animate the ImageObserver will have to be specified instead of being set to null and then repaint must be called when imageUpdate() is called on the ImageObserver.

An example of displaying an animated gif can be viewed here: Relationship Between Animated Gif and Image Observer

So as far as I can see you will either have to change the above NetBeans platform code and rebuild it for your application or you will have to create your own splash screen from scratch to use instead of the NetBeans one.

Hope you find this useful!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top