This issue was found on analysing the ignored Spinner test as part of JDK-8328667
Listener added to valueProperty of the spinner is not invoked on changing the spinner value using getEditor().setText() method.
Steps to reproduce the issue:
Run the source code given below.
Notice that the spinner value displayed on console is 5 where as the value displayed in Spinner is 3.
On changing the value manually using spinner, it changes from 5 instead of 3.
-----BEGIN SOURCE-----
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class SpinnerSample extends Application {
int count = 0;
public void start(Stage stage) {
Spinner<Integer> spinner = new Spinner<>(0, 10, 5, 1);
spinner.valueProperty().addListener(o -> {
System.out.println("Listener invoked");
System.out.println((int)spinner.getValue());
count++;
});
spinner.getEditor().setText("3");
System.out.println(count);
System.out.println((int)spinner.getValue());
VBox vBox = new VBox(spinner);
Scene scene = new Scene(vBox, 400, 200);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
-----END SOURCE-----
Listener added to valueProperty of the spinner is not invoked on changing the spinner value using getEditor().setText() method.
Steps to reproduce the issue:
Run the source code given below.
Notice that the spinner value displayed on console is 5 where as the value displayed in Spinner is 3.
On changing the value manually using spinner, it changes from 5 instead of 3.
-----BEGIN SOURCE-----
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class SpinnerSample extends Application {
int count = 0;
public void start(Stage stage) {
Spinner<Integer> spinner = new Spinner<>(0, 10, 5, 1);
spinner.valueProperty().addListener(o -> {
System.out.println("Listener invoked");
System.out.println((int)spinner.getValue());
count++;
});
spinner.getEditor().setText("3");
System.out.println(count);
System.out.println((int)spinner.getValue());
VBox vBox = new VBox(spinner);
Scene scene = new Scene(vBox, 400, 200);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
-----END SOURCE-----
- relates to
-
JDK-8328667 [Testbug] Enable ignored Spinner unit tests
- Resolved