JDK-8092295 : [ComboBox, DatePicker] The DatePicker does not update its value on focus lost, and there is no way to force an update.
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8u40
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2015-03-27
  • Updated: 2016-09-20
  • Resolved: 2015-10-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Duplicate :  
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.
Comments
Duplicate of JDK-8136838.
16-10-2015

Another workaround is: 5. Listen to changes on the value property instead of focus.
27-03-2015

It won't be possible to change the default behavior so that the value is updated on every keystroke, as it may affect existing applications and either break them or slow them down. We can consider adding a public method to commit the current text value as suggested, and/or add a property to allow the immediate behavior. There are several possible workarounds at this point. 1. Get the value in a runLater(). 2. Fire a KeyCode.ENTER event at the DatePicker. 3. Apply the value explicitly: datePicker.setValue(datePicker.getConverter().fromString(datePicker.getEditor().getText())); 4. Possibly do #3 in a key listener on the editor if desired. Just make sure to catch parse exceptions from the converter in this case.
27-03-2015