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

[ComboBox, DatePicker] The DatePicker does not update its value on focus lost, and there is no way to force an update.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P5
    • Resolution: Duplicate
    • Affects Version/s: 8u40
    • Fix Version/s: 9
    • Component/s: javafx
    • Environment:

      Microsoft Windows 7; Java 8u40

      Description

      The DatePicker does not immediately commit/update the value whenever the text in the TextField changes. This can lead to situations where the old value is being retrieved from the DatePicker.

      There should be a way to commit the changes, ideally something like a commit() method that allows that. Or the DatePicker should internally listen for changes in the TextField and try to update its value.

      Here is a sample application showing the problem:

      package application;


      import java.util.Objects;

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.scene.Scene;
      import javafx.scene.control.DatePicker;
      import javafx.scene.control.Label;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class Main extends Application {
      public static void main(String[] args) {
      launch(args);
      }

      @Override
      public void start(Stage primaryStage) {
      DatePicker datePicker = new DatePicker();
      datePicker.focusedProperty().addListener((ov, o, n) -> System.out.println("DatePicker Focus: " + o + " -> " + n + " / " + Objects.toString(datePicker.getValue())));

      TextField textField = new TextField("You can set the focus here.");
      textField.focusedProperty().addListener((ov, o, n) -> System.out.println("TextField Focus: " + o + " -> " + n + " / " + Objects.toString(datePicker.getValue())));

      Label label = new Label();

      BorderPane root = new BorderPane();
      root.setTop(textField);
      root.setCenter(datePicker);
      root.setBottom(label);

      new Thread(() -> {
      while (true) {
      Platform.runLater(() -> label.setText(Objects.toString(datePicker.getValue())));

      try {
      Thread.sleep(1);
      } catch (Exception e) {
      e.printStackTrace();
      }
      }
      }).start();

      Scene scene = new Scene(root, 640, 480);

      primaryStage.setScene(scene);
      primaryStage.show();
      }

      }

      Steps to reproduce:

       1. Select a date in the DatePicker (for example with the popup) and hit ENTER.
       2. Change the value by only typing, do not hit ENTER.
       3. Change the focus to the TextField.

      What happens is that the DatePicker focus listener is fired with the correct focus change (true to false), but the value is still the old one. This is especially problematic if there is "work" to be done if the DatePicker loses the focus and there is not the correct value set.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                leifs Leif Samuelsson (Inactive)
                Reporter:
                rzenzjfx Robert Zenz (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported: