Package com.dua3.utility.fx
Class PlatformHelper
java.lang.Object
com.dua3.utility.fx.PlatformHelper
The PlatformHelper class provides utility methods for performing tasks on the JavaFX application thread.
It provides methods for running tasks synchronously or asynchronously on the JavaFX application thread,
as well as checking if the current thread is the FX Application Thread.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidChecks if the current thread is the FX Application Thread.static voidrunAndWait(Runnable action) Run a task on the JavaFX application thread and wait for completion.static <T extends @Nullable Object>
TrunAndWait(Supplier<T> action) Run a task on the JavaFX application thread and return the result.static voidRun a task on the JavaFX application thread and log any exceptions.static voidRun a task on the JavaFX application thread and handle any exceptions.static booleanShut down the JavaFX platform.
-
Method Details
-
runAndWait
Run a task on the JavaFX application thread and wait for completion.Note:
- This method will block the calling thread until the task completes.
- Any runtime exceptions thrown by the task will be rethrown by this method.
- Consider using
runLater(Runnable)to avoid executing tasks out of order.
- Parameters:
action- the task to run- Throws:
NullPointerException- ifactionisnullRuntimeException- if the task throws one
-
runAndWait
Run a task on the JavaFX application thread and return the result.Note:
- This method will block the calling thread until the task completes.
- Any runtime exceptions thrown by the task will be rethrown by this method.
- Consider using
runLater(Runnable)to avoid executing tasks out of order.
- Type Parameters:
T- the result type- Parameters:
action- the task to run- Returns:
- the result returned by action
- Throws:
NullPointerException- ifactionisnullRuntimeException- if the task throws one
-
runLater
Run a task on the JavaFX application thread and log any exceptions.- Parameters:
action- the task to run- Throws:
NullPointerException- ifactionisnull
-
runLater
Run a task on the JavaFX application thread and handle any exceptions.Note that the error handler is called on the JavaFX application thread son there is no use in simply mapping the exception to a different type. Also it is not possible to pass the exception to the caller as the task is run asynchronously.
If the exception should be thrown to the caller,
runAndWait(Runnable)has to be used instead.- Parameters:
action- the task to runerrorHandler- the error handler to use- Throws:
NullPointerException- ifactionisnull
-
checkApplicationThread
public static void checkApplicationThread()Checks if the current thread is the FX Application Thread. Throws an exception if it is not. -
shutdown
Shut down the JavaFX platform.- Parameters:
timeout- the maximum time to wait for the platform to shut downunit- the time unit of the timeout argument- Returns:
- true if the platform shut down within the timeout, false otherwise
-