-
Bug
-
Resolution: Duplicate
-
P5
-
8u40
-
Microsoft Windows 7; Java 8u40
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.
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.
- duplicates
-
JDK-8136838 [ComboBox, DatePicker] Value doesn't update when focus is lost
-
- Resolved
-