Class FXUtils
- java.lang.Object
-
- org.testfx.framework.junit5.utils.FXUtils
-
public final class FXUtils extends java.lang.Object
Small tool to execute/call JavaFX GUI-related code from potentially non-JavaFX thread (equivalent to old: SwingUtilities.invokeLater(...) ... invokeAndWait(...) tools)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FXUtils.ExceptionWrapper
private static class
FXUtils.RunnableWithReturn<R>
-
Constructor Summary
Constructors Constructor Description FXUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertJavaFxThread()
static void
keepJavaFxAlive()
If you run into any situation where all of your scenes end, the thread managing all of this will just peter out.static void
runAndWait(java.lang.Runnable function)
Invokes a Runnable in JFX Thread and waits while it's finished.static <R> R
runAndWait(java.util.function.Supplier<R> function)
Invokes a Runnable in JFX Thread and waits while it's finished.static <T,R>
RrunAndWait(T argument, java.util.function.Function<T,R> function)
Invokes a Runnable in JFX Thread and waits while it's finished.static void
runFX(java.lang.Runnable run)
-
-
-
Method Detail
-
assertJavaFxThread
public static void assertJavaFxThread()
-
keepJavaFxAlive
public static void keepJavaFxAlive()
If you run into any situation where all of your scenes end, the thread managing all of this will just peter out. To prevent this from happening, add this line:
-
runAndWait
public static void runAndWait(java.lang.Runnable function) throws java.lang.Exception
Invokes a Runnable in JFX Thread and waits while it's finished. Like SwingUtilities.invokeAndWait does for EDT.- Parameters:
function
- Runnable function that should be executed within the JavaFX thread- Throws:
java.lang.Exception
- if a exception is occurred in the run method of the Runnable
-
runAndWait
public static <R> R runAndWait(java.util.function.Supplier<R> function) throws java.lang.Exception
Invokes a Runnable in JFX Thread and waits while it's finished. Like SwingUtilities.invokeAndWait does for EDT.- Type Parameters:
R
- generic for return type- Parameters:
function
- Supplier function that should be executed within the JavaFX thread- Returns:
- function result of type R
- Throws:
java.lang.Exception
- if a exception is occurred in the run method of the Runnable
-
runAndWait
public static <T,R> R runAndWait(T argument, java.util.function.Function<T,R> function) throws java.lang.Exception
Invokes a Runnable in JFX Thread and waits while it's finished. Like SwingUtilities.invokeAndWait does for EDT.- Type Parameters:
T
- generic for argument typeR
- generic for return type- Parameters:
argument
- function argumentfunction
- transform function that should be executed within the JavaFX thread- Returns:
- function result of type R
- Throws:
java.lang.Exception
- if a exception is occurred in the run method of the Runnable
-
runFX
public static void runFX(java.lang.Runnable run)
-
-