title: Wait for JavaFX Application Thread to finish handling events?
body: <p>Lots of questions on here are asking about how to pause the JavaFX Application thread for a background thread, but I want the opposite!</p>
  
  <p>I'm trying to test how long it takes for a series of key inputs to be fully handled. I am using the <a href="https://github.com/renatoathaydes/Automaton" rel="nofollow">Automaton</a> testing library for JavaFX, and editor.type(key) generates a keypress event that gets processed by the application. Here is one of many attempts:</p>
  
  <pre><code>long start = System.nanoTime();
  
  editor.type(AGUtils.LEFT_ARROW);
  editor.type(AGUtils.LEFT_ARROW);
  editor.type(AGUtils.RIGHT_ARROW);
  editor.type(AGUtils.RIGHT_ARROW);
  
  FutureTask&lt;Callable&gt; t = new FutureTask&lt;&gt;(...);
  Platform.runLater(t);
  
  while (!t.isDone()) { } // wait for the FutureTask to be called
  
  long end = System.nanoTime();
  </code></pre>
  
  <p>However, it seems the FX Application Thread might be handling the FutureTask before it handles the rest of the keypress events.</p>
  
  <p>TLDR: I want to precisely measure when the JavaFX Application Thread has finished handling the four keypress events I generate.</p>
  
  <p>How can I go about this? Thank you!</p>