JavaFX: Update ProgressBar (@FXML) from Thread
<p>I want to update a JavaFX ProgressBar defined in an FXML file by another class, initialized in a controller thread. Currently it just does not update.</p>

<p><strong>test.fxml</strong></p>

<pre class="lang-xml prettyprint-override"><code>&lt;ProgressBar fx:id="progressBar" prefWidth="5000.0" progress="0.0"&gt;
    &lt;VBox.margin&gt;
        &lt;Insets top="3.0" /&gt;
    &lt;/VBox.margin&gt;
&lt;/ProgressBar&gt;
</code></pre>

<p><strong>Controller.java</strong></p>

<pre><code>@FXML
public static ProgressBar progressBar = new ProgressBar(0);

MyMain main;

@FXML
private void handleStartWork() throws Exception {
    new Thread() {
        @Override
        public void run() {
            try {
                main = new MyMain();
                main.doIt();
            } catch (final Exception v) {
                // ...
            }
        }
    }.start();
}
</code></pre>

<p><strong>MyMain.java</strong></p>

<pre><code>public void doIt(){
    while(...){
        Platform.runLater(() -&gt; PoCOverviewController.progressBar.setProgress((count / sum) * 100));
    }
}
</code></pre>

<p>I already tried different versions in consideration of posts like:</p>

<ul>
<li><a href="https://stackoverflow.com/questions/29854627/progressbar-doesnt-work-with-a-fxml-file-and-a-controller">ProgressBar doesn't work with a fxml file and a controller</a></li>
<li><a href="https://stackoverflow.com/questions/17109413/how-to-configure-progress-bar-and-progress-indicator-of-javafx">How to configure Progress Bar and Progress Indicator of javaFx?</a></li>
</ul>

<p>I don't know if it's the right approach to make the ProgressBar static. I just did not want to pass the Object through the workflow.  </p>

<p><strong>Update (Xavier Lambros answer)</strong>:
Now i tried it with singleton but it's still not working:</p>

<p><strong>Controller.java</strong></p>

<pre><code>@FXML
public ProgressBar progressBar = new ProgressBar(0);    

private static Controller INSTANCE = new Controller();

public static Controller getInstance() {
    return INSTANCE;
}

public ProgressBar getProgressBar() {
    return progressBar;
}
</code></pre>

<p><strong>MyMain.java</strong></p>

<pre><code>public void doIt(){
    while(...){
        Platform.runLater(() -&gt; Controller.getInstance().getProgressBar()
                .setProgress((count / sum) * 100));
    }
}
</code></pre>