Class FXUtils

java.lang.Object
org.testfx.framework.junit5.utils.FXUtils

public final class FXUtils extends Object
Small tool to execute/call JavaFX GUI-related code from potentially non-JavaFX thread (equivalent to old: SwingUtilities.invokeLater(...) ... invokeAndWait(...) tools)
  • Constructor Details

    • FXUtils

      public FXUtils()
  • Method Details

    • 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(Runnable function) throws 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:
      Exception - if a exception is occurred in the run method of the Runnable
    • runAndWait

      public static <R> R runAndWait(Supplier<R> function) throws 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:
      Exception - if a exception is occurred in the run method of the Runnable
    • runAndWait

      public static <T, R> R runAndWait(T argument, Function<T,R> function) throws 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 type
      R - generic for return type
      Parameters:
      argument - function argument
      function - transform function that should be executed within the JavaFX thread
      Returns:
      function result of type R
      Throws:
      Exception - if a exception is occurred in the run method of the Runnable
    • runFX

      public static void runFX(Runnable run)