When a spinner is configured with e.g. integers (IntegerSpinnerValueFactory) and the user types in a String, e.g. 'abc' and focus another node, an exception is thrown (NumberFormatException).
The exception is thrown from a 'lost focus' event handler declared in the Spinner constructor and so cannot be caught by any obvious mechanism.
This is the same issue asJDK-8303478, which is for the DatePicker component.
In the example below, just type a String like 'abc' into the Spinner and click the Button next to it. You can see an exception in the console (NumberFormatException).
### SOURCE ###
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class SpinnerBug extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
Spinner<Integer> spinner = new Spinner<>(new IntegerSpinnerValueFactory(0, 10, 0));
spinner.setEditable(true);
Button button = new Button("Focus me");
final Scene sc = new Scene(new HBox(spinner, button));
primaryStage.setScene(sc);
primaryStage.show();
}
public static void main(final String[] args) {
Application.launch(args);
}
}
### SOURCE END ###
The exception is thrown from a 'lost focus' event handler declared in the Spinner constructor and so cannot be caught by any obvious mechanism.
This is the same issue as
In the example below, just type a String like 'abc' into the Spinner and click the Button next to it. You can see an exception in the console (NumberFormatException).
### SOURCE ###
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class SpinnerBug extends Application {
@Override
public void start(final Stage primaryStage) throws Exception {
Spinner<Integer> spinner = new Spinner<>(new IntegerSpinnerValueFactory(0, 10, 0));
spinner.setEditable(true);
Button button = new Button("Focus me");
final Scene sc = new Scene(new HBox(spinner, button));
primaryStage.setScene(sc);
primaryStage.show();
}
public static void main(final String[] args) {
Application.launch(args);
}
}
### SOURCE END ###
- relates to
-
JDK-8303478 DatePicker throws uncatchable exception on tab out from garbled text
- Resolved
- links to
-
Commit openjdk/jfx/49d7d52f
-
Review(master) openjdk/jfx/1365