title: How do I put something on an FX thread?
body: <p>I'm new to JavaFX (trying to move from Swing), and am trying to make a very basic window first. However, I keep getting the following runtime exception:</p>
  
  <pre class="lang-none prettyprint-override"><code>Exception in thread "main" java.lang.IllegalStateException: Not on FX application thread; currentThread = main
      at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:210)
      at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:393)
      at javafx.scene.Scene.&lt;init&gt;(Scene.java:374)
      at javafx.scene.Scene.&lt;init&gt;(Scene.java:232)
      at bht.tools.util.upd.TestDialog.initGUI(TestDialog.java:39)
      at bht.tools.util.upd.TestDialog.&lt;init&gt;(TestDialog.java:24)
      at bht.tools.util.upd.TestDialog.main(TestDialog.java:52)
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>package bht.tools.util.upd;
  
  import java.awt.Window;
  import javafx.embed.swing.JFXPanel;
  import javafx.scene.Scene;
  import javafx.scene.control.*;
  import javafx.scene.layout.GridPane;
  import javax.swing.JDialog;
  
  /**
   * TestDialog is copyright Blue Husky Programming ©2014 GPLv3 &lt;hr/&gt;
   * 
   * @author Kyli of Blue Husky Programming
   * @version 1.0.0
   *      - 2014-09-30 (1.0.0) - Kyli created TestDialog
   * @since 2014-09-30
   */
  public class TestDialog extends JDialog
  {
      public TestDialog(Window owner)
      {
          super(owner);
          initGUI();
      }
  
      private JFXPanel holder;
      private Scene interior;
      private ProgressBar progressBar;
      private GridPane root;
      private void initGUI()
      {
          {
              holder = new JFXPanel();
              setContentPane(holder);
              root = new GridPane();
              interior = holder.getScene();
              if (interior == null)
                  holder.setScene(interior = new Scene(root));
              interior.setRoot(root);
          }
          {
              progressBar = new ProgressBar();
              progressBar.setProgress(-1);
              root.add(progressBar, 0, 1);
          }
          pack();
      }
  
      public static void main(String[] args)
      {
          new TestDialog(null).setVisible(true);
      }
  }
  </code></pre>
  
  <p>However, looking at the <code>JFXPanel</code> source code, the constructor calls its <code>initFX()</code> method, which initializes the FX application thread. <strong>Why, then, am I getting this error, and how do I fix it?</strong></p>