0

I'm wondering how to set the value of a JavaFX Spinner directly from the UI. As I have it now, I have to use the buttons up and down to change it, when I set directly it's not being updated.

I know with Swing you can just use spinner#setValue but it seems to be different with JavaFX.

Fxml:

<Spinner fx:id="spinnerClusters" editable="true" prefHeight="25.0" prefWidth="107.0">
    <HBox.margin>
        <Insets left="10.0" />
    </HBox.margin>
</Spinner>

Controller:

    public void initialize(URL url, ResourceBundle rb) {
            spinnerClusters.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 100, 0));      
        }
////
    int value = spinnerNBClusters.getValue();

How can I make the value change if the user inputs it directly into the spinner field?

AbdelKh
  • 499
  • 7
  • 19
  • Press "Enter". It's a bug in Java 8, should be fixed in 9: https://bugs.openjdk.java.net/browse/JDK-8150946 . – Itai May 06 '17 at 16:53
  • Possible duplicate of [Manually typing in text in JavaFX Spinner is not updating the value (unless user presses ENTER)](http://stackoverflow.com/questions/32340476/manually-typing-in-text-in-javafx-spinner-is-not-updating-the-value-unless-user) – Itai May 06 '17 at 16:54

1 Answers1

0

As sillyfly draw my attention to, it is a bug in Java 8.

The solution is to press "Enter".

It should be fixed in Java 9:

bugs.openjdk.java.net/browse/JDK-8150946

AbdelKh
  • 499
  • 7
  • 19