Class Platform

java.lang.Object
javafx.application.Platform

public final class Platform extends Object
Application platform support class.
Since:
JavaFX 2.0
  • Method Details

    • runLater

      public static void runLater(Runnable runnable)
      Run the specified Runnable on the JavaFX Application Thread at some unspecified time in the future. This method, which may be called from any thread, will post the Runnable to an event queue and then return immediately to the caller. The Runnables are executed in the order they are posted. A runnable passed into the runLater method will be executed before any Runnable passed into a subsequent call to runLater. If this method is called after the JavaFX runtime has been shutdown, the call will be ignored: the Runnable will not be executed and no exception will be thrown.

      NOTE: applications should avoid flooding JavaFX with too many pending Runnables. Otherwise, the application may become unresponsive. Applications are encouraged to batch up multiple operations into fewer runLater calls. Additionally, long-running operations should be done on a background thread where possible, freeing up the JavaFX Application Thread for GUI operations.

      This method must not be called before the FX runtime has been initialized. For standard JavaFX applications that extend , and use either the Java launcher or one of the launch methods in the Application class to launch the application, the FX runtime is initialized by the launcher before the Application class is loaded. For Swing applications that use JFXPanel to display FX content, the FX runtime is initialized when the first JFXPanel instance is constructed. For SWT application that use FXCanvas to display FX content, the FX runtime is initialized when the first FXCanvas instance is constructed.

      Parameters:
      runnable - the Runnable whose run method will be executed on the JavaFX Application Thread
      Throws:
      IllegalStateException - if the FX runtime has not been initialized
    • isFxApplicationThread

      public static boolean isFxApplicationThread()
      Returns true if the calling thread is the JavaFX Application Thread. Use this call the ensure that a given task is being executed (or not being executed) on the JavaFX Application Thread.
      Returns:
      true if running on the JavaFX Application Thread
    • exit

      public static void exit()
      Causes the JavaFX application to terminate. If this method is called after the Application start method is called, then the JavaFX launcher will call the Application stop method and terminate the JavaFX application thread. The launcher thread will then shutdown. If there are no other non-daemon threads that are running, the Java VM will exit. If this method is called from the Preloader or the Application init method, then the Application stop method may not be called.

      This method may be called from any thread.

      Note: if the application is embedded in a browser, then this method may have no effect.