Why doesn't my Spinner update its bound property the first time it is initialized?
<p>I have a <code>Spinner</code> in controller:</p>

<pre><code>@FXML
private Spinner&lt;Integer&gt; spnMySpinner;
</code></pre>

<p>and a <code>SimpleIntegerProperty</code>in controller:</p>

<pre><code>private static final SimpleIntegerProperty myValue = 
new SimpleIntegerProperty(3); //load a default value
</code></pre>

<p>I have bound them together in controller's <code>initialize</code> method:</p>

<pre><code>spnMySpinner.getValueFactory().valueProperty().bindBidirectional(myValueProperty().asObject());
</code></pre>

<p>But the bindings work correctly only after second time the controller initializes. Here's how I can reproduce it:</p>

<ol>
<li>I open the stage with the associated controller, it loads the default value, specified in the <code>myValue</code> property correctly (a number 3).</li>
<li>I click the increment button on the spinner to make it a 4. It changes the value in the spinner's value property, but the bound property <code>myValue</code> is left intact with the number 3.</li>
<li>I close the stage/window.</li>
<li>I reopen it, the spinner has again a value of 3.</li>
<li>I increment it again. Boom now the binding works and I have a "4" both inside the spinner and the bound property.</li>
</ol>

<p>Entire minimalistic, but launchable/reproducible code:</p>

<p>Main.java:</p>

<pre><code>package spinnerpoc;

import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage stage) throws IOException {
        Parent root  = FXMLLoader.load(getClass().getResource("MainWindow.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }

}
</code></pre>

<p>MainWindow.fxml:</p>

<pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;?import javafx.scene.control.Button?&gt;
&lt;?import javafx.scene.layout.AnchorPane?&gt;


&lt;AnchorPane fx:id="myRoot" id="AnchorPane" prefHeight="231.0" prefWidth="337.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.60" fx:controller="spinnerpoc.MainWindowController"&gt;
    &lt;children&gt;
        &lt;Button fx:id="btnOpenSpinnerWindow" layoutX="102.0" layoutY="103.0" mnemonicParsing="false" text="Open SpinnerWindow" onAction="#onOpenSpinnerWindow"/&gt;
    &lt;/children&gt;
&lt;/AnchorPane&gt;
</code></pre>

<p>MainWindowController.java:</p>

<pre><code>package spinnerpoc;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Modality;
import javafx.stage.Stage;

public class MainWindowController implements Initializable {

    @FXML
    private Button btnOpenSpinnerWindow;
    @FXML
    private AnchorPane myRoot;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
    }

    @FXML
    private void onOpenSpinnerWindow(ActionEvent event) throws IOException{
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("SpinnerWindow.fxml"));
        Parent root = (Parent) fxmlLoader.load();
        Stage stage = new Stage();
        stage.initOwner(myRoot.getScene().getWindow());
        stage.initModality(Modality.WINDOW_MODAL);
        stage.setTitle("SpinnerWindow");
        stage.setScene(new Scene(root));
        stage.show();
    }

}
</code></pre>

<p>SpinnerWindow.fxml:</p>

<pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;?import javafx.scene.control.Button?&gt;
&lt;?import javafx.scene.control.Label?&gt;
&lt;?import javafx.scene.control.RadioButton?&gt;
&lt;?import javafx.scene.control.ScrollPane?&gt;
&lt;?import javafx.scene.control.Slider?&gt;
&lt;?import javafx.scene.control.Spinner?&gt;
&lt;?import javafx.scene.control.SpinnerValueFactory.DoubleSpinnerValueFactory?&gt;
&lt;?import javafx.scene.control.TitledPane?&gt;
&lt;?import javafx.scene.control.ToggleGroup?&gt;
&lt;?import javafx.scene.layout.HBox?&gt;
&lt;?import javafx.scene.layout.VBox?&gt;


&lt;ScrollPane xmlns:fx="http://javafx.com/fxml/1" fitToWidth="true" prefHeight="200.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/8.0.60" fx:controller="spinnerpoc.SpinnerWindowController"&gt;
    &lt;content&gt;
        &lt;VBox maxWidth="1.7976931348623157E308"&gt;
            &lt;children&gt;
                &lt;Spinner fx:id="spnMySpinner" editable="true" prefWidth="50.0" max="10" min="1" /&gt;
            &lt;/children&gt;
        &lt;/VBox&gt;
    &lt;/content&gt;
&lt;/ScrollPane&gt;
</code></pre>

<p>SpinnerWindowController.java:</p>

<pre><code>package spinnerpoc;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Spinner;

public class SpinnerWindowController implements Initializable {

    private static final SimpleIntegerProperty myValue = new SimpleIntegerProperty(3);

    public static SimpleIntegerProperty myValueProperty() {
        return myValue;
    }

    public static Integer getMyValue() {
        return myValue.getValue();
    }

    public static void setMyValue(int value) {
        myValue.set(value);
    }

    @FXML
    private Spinner&lt;Integer&gt; spnMySpinner;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        spnMySpinner.getValueFactory().valueProperty().bindBidirectional(myValueProperty().asObject());
    }

}
</code></pre>

<p>(Code also available at a <a href="https://bitbucket.org/Leprechaunius/spinnerpoc/src/446228851e5dad6efaf64e065d89099b44416158/src/spinnerpoc/?at=master" rel="nofollow">BitBucket repo</a>.)</p>

<p>What am I missing?</p>