diff --git a/modules/graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java b/modules/graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java --- a/modules/graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java +++ b/modules/graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java @@ -133,7 +133,8 @@ /** * This method is invoked typically on the main thread. At this point, * the JavaFX Application Thread has not been started. Any attempt - * to call startup twice results in an exception. + * to call startup more than once results in all subsequent calls turning into + * nothing more than a runLater call with the provided Runnable being called. * @param r */ public static void startup(final Runnable r) { diff --git a/modules/graphics/src/main/java/javafx/application/Platform.java b/modules/graphics/src/main/java/javafx/application/Platform.java --- a/modules/graphics/src/main/java/javafx/application/Platform.java +++ b/modules/graphics/src/main/java/javafx/application/Platform.java @@ -40,6 +40,53 @@ } /** + * This method starts the JavaFX runtime. In general it is not necessary to + * explicitly call this method (it is generally invoked as a consequence of + * how most JavaFX applications are built), however there are valid use cases + * for calling this method directly. Because this method starts the JavaFX + * runtime, there is not yet any JavaFX Application Thread, so it is normal + * that this method is called directly on the main thread of the application. + * + *
As noted, it is normally the case that the JavaFX Application Thread + * is started automatically. It is important that this method only be called + * when the JavaFX runtime has not yet been initialized. Situations where + * the JavaFX runtime is started automatically include: + * + *
When an application does not follow any of these common approaches, + * then it becomes the responsibility of the developer to manually start the + * JavaFX runtime by calling this startup method. + * + *
Calling this method multiple times is discouraged, but will have no + * effect beyond placing the provided Runnable onto the event queue (in + * other words, it becomes equivalent to calling {@link #runLater(Runnable)}. + * For this reason, it is highly recommended that the startup method only + * be called once, with all subsequent uses instead making use of + * {@link #runLater(Runnable)}. + *
+ * + * @param runnable the Runnable whose run method will be executed on the + * JavaFX Application Thread once it has been started. + * @since 9 + */ + public static void startup(Runnable runnable) { + PlatformImpl.startup(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, @@ -72,6 +119,9 @@ * 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. + * For applications that do not follow any of these approaches, then it is + * necessary to manually start the JavaFX runtime by calling + * {@link #startup(Runnable)} once. * * * @param runnable the Runnable whose run method will be executed on the