Class Preloader



  • public abstract class Preloader
    extends Application
    Class that is extended to define an optional preloader for a JavaFX Application. An application may contain a preloader that is used to improve the application loading experience, especially for applications that are embedded in a browser or launched in webstart execution mode.

    A preloader is a small application that is started before the main application to customize the startup experience. The preloader:

    • gets notification of progress of loading application resources
    • gets notification of errors
    • gets notification of application initialization and startup
    • decides when application should become visible

    The default preloader is shown on top of the application Stage, which is not visible until the preloader is visible. The preloader need to hide itself to make the application visible. Good practice is to do this no earlier than right before application.start() is called, as otherwise application itself is not visible.

    The preloader may also cooperate with the application to achieve advanced visual effects or share data (e.g. to implement login screen). The preloader gets a reference to the application and may pull data it needs for cooperation from the application if the application implements an interface that the preloader knows about and relies upon. Generally it is not recommended to design preloaders in such a way that an application would call them directly, as this will result in bad user experience if the application is signed and the preloader is not.

    If the application does not specify a preloader, then the default preloader is used. Default preloader appearance can be customized (set of parameters is TBD).

    Custom preloader implementations should follow these rules:

    1. there should be class extending Preloader
    2. classes needed for preloader need to be packaged in the separate jar. We recommend this jar to be unsigned.
    3. JNLP deployment descriptor should have preloader-class attribute with full name of the class as value in the javafx-desc element and jars needed for progress need to have download="progress" type

    Applications may also send custom notification to the preloader using the notifyPreloader method. This way a preloader may also show application initialization progress.

    Note that preloaders are subject to the same rules as other JavaFX applications including FX threading rules. In particular, the class constructor and init() method will be called on a non-FX thread and start() will be executed on the FX application thread. This also means that the application constructor/init() will run concurrently with preloader start().

    Callbacks on preloader notification will be delivered on the FX application thread.

    Shutdown (including when stop() is called) is TBD.

    Since:
    JavaFX 2.0
    • Constructor Detail

      • Preloader

        public Preloader​()
    • Method Detail

      • handleProgressNotification

        public void handleProgressNotification​(Preloader.ProgressNotification info)
        Indicates download progress. This method is called by the FX runtime to indicate progress while application resources are being loaded. It will not be called to deliver a ProgressNotification sent to notifyPreloader.

        The implementation of this method provided by the Preloader class does nothing.

        Parameters:
        info - the progress notification
      • handleStateChangeNotification

        public void handleStateChangeNotification​(Preloader.StateChangeNotification info)
        Indicates a change in application state. This method is called by the FX runtime as part of the application life-cycle.

        The implementation of this method provided by the Preloader class does nothing.

        Parameters:
        info - the state change notification
      • handleApplicationNotification

        public void handleApplicationNotification​(Preloader.PreloaderNotification info)
        Indicates an application-generated notification. This method is called by the FX runtime to deliver a notification sent via notifyPreloader.

        Applications should not call this method directly, but should use notifyPreloader instead to avoid mixed code dialog issues.

        The implementation of this method provided by the Preloader class does nothing.

        Parameters:
        info - the application-generated notification
      • handleErrorNotification

        public boolean handleErrorNotification​(Preloader.ErrorNotification info)
        Called when an error occurs.

        The implementation of this method provided by the Preloader class returns false, indicating that the default error handler should show the message to the user.

        Parameters:
        info - the error notification describing the cause of this error
        Returns:
        true if error was shown to the user by preloader and no additional visualization is needed; otherwise, false.