Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8325798

Spinner throws uncatchable exception on tab out from garbled text

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • jfx23
    • jfx11, jfx17, jfx21, jfx22
    • javafx
    • None
    • b05
    • generic
    • generic

      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 as JDK-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 ###

            mhanl Marius Hanl
            mhanl Marius Hanl
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: