Module javafx.graphics
Package javafx.application

## Class Preloader

- java.lang.Object
- - javafx.application.Application
  - - javafx.application.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.

  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. a custom preloader class should extend Preloader
  2. classes needed for preloader need to be packaged in the separate jar.

  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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `Preloader.ErrorNotification` | Preloader notification that reports an error.
    `static interface` | `Preloader.PreloaderNotification` | Marker interface for all Preloader notification.
    `static class` | `Preloader.ProgressNotification` | Preloader notification that reports progress.
    `static class` | `Preloader.StateChangeNotification` | A notification that signals a change in the application state.

    - ### Nested classes/interfaces inherited from class javafx.application.Application

      `Application.Parameters`

  - ### Field Summary

    - ### Fields inherited from class javafx.application.Application

      `STYLESHEET_CASPIAN, STYLESHEET_MODENA`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Preloader()` |

  - ### Method Summary

    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `handleApplicationNotification​(Preloader.PreloaderNotification info)` | Indicates an application-generated notification.
    `boolean` | `handleErrorNotification​(Preloader.ErrorNotification info)` | Called when an error occurs.
    `void` | `handleProgressNotification​(Preloader.ProgressNotification info)` | Indicates download progress.
    `void` | `handleStateChangeNotification​(Preloader.StateChangeNotification info)` | Indicates a change in application state.

    - ### Methods inherited from class javafx.application.Application

      `getHostServices, getParameters, getUserAgentStylesheet, init, launch, launch, notifyPreloader, setUserAgentStylesheet, start, stop`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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.