title: JavaFX Thread freeze
body: <p>I'm currently working on a JavaFX project. On GUI initialization I want to read some infos out of a HTML document using Selenium and FirefoxDriver. Normally I would use a crawler to get the infos but this document is full of JavaScript so I was only able to get to the infos using Selenium (I know, it's really bad). </p>
  
  <p>Now I've got the problem that this process takes up to 15 seconds and I want to show the progress of Selenium on a JavaFX progress bar. So I've set up a Thread doing all the work and trying to update the GUI but the Thread freezes until Selenium is finished.</p>
  
  <p>This is my attempt:</p>
  
  <pre><code>public class SeleniumThread extends Thread
  {
      private MainViewController main;
  
      @Override
      public void run()
      {
          try
          {
              WebDriver driver = new FirefoxDriver();
              driver.get("http://---.jsp");
              main.getMain().getPrimaryStage().toFront();
              main.getPbStart().setProgress(0.1);
              WebElement query = driver.findElement(By.id("user"));
              query.sendKeys(new String[] {"Username"});
              query = driver.findElement(By.id("passwd"));
              query.sendKeys(new String[] {"Password"});
              query.submit();
              driver.get("http://---.jsp");
              main.getPbStart().setProgress(0.2);
              sleep(1000);
              main.getPbStart().setProgress(0.25);
              driver.get("http://---.jsp");
              main.getPbStart().setProgress(0.4);
              sleep(1000);
              main.getPbStart().setProgress(0.45);
              driver.get("---.jsp");
              main.getPbStart().setProgress(0.6);
              sleep(1000);
              main.getPbStart().setProgress(0.65);
              query = driver.findElement(By.cssSelector("button.xyz"));
              query.click();
              sleep(1000);
              main.getPbStart().setProgress(0.85);
              System.out.println(driver.getPageSource());
              driver.quit();
          }
          catch(InterruptedException e)
          {
              // Exception ...
          }
  
      }
  
      public MainViewController getMain()
      {
          return main;
      }
  
      public void setMain(MainViewController main)
      {
          this.main = main;
      }
  }
  </code></pre>
  
  <p>MainViewController</p>
  
  <pre><code>public void startup()
  {
      if(main.getCc().getMjUsername() != null &amp;&amp;
              main.getCc().getMjPassword() != null &amp;&amp;
              main.getCc().getMjUsername().length() != 0 &amp;&amp;
              main.getCc().getMjPassword().length() != 0)
      {
          SeleniumThread st = new SeleniumThread();
          st.setMain(this);
          st.setDaemon(true);
          st.run();
      }
  }
  </code></pre>
  
  <p>I've read that I should use a Worker like Task for it, but I have no clue how to implement it. And I need to pass a parameter to this Task, because I need to set my primaryStage to the front and update the progress bar.</p>
  
  <p>I hope you can understand my problem. I'd be grateful for every help.</p>