diff --git a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java --- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java +++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java @@ -101,10 +101,7 @@ KeyEvent ke = (KeyEvent)t; if (ke.getCode() == KeyCode.ENTER) { - StringConverter c = comboBox.getConverter(); - if (c == null) return; - T value = c.fromString(textField.getText()); - comboBox.setValue(value); + setTextFromTextFieldIntoComboBoxValue(); t.consume(); return; } else if (ke.getCode() == KeyCode.F4 && ke.getEventType() == KeyEvent.KEY_RELEASED) { @@ -236,11 +233,18 @@ // focus always goes to the comboBox, which then forwards events down // to the TextField. This ensures that the ComboBox appears focused // externally for people listening to the focus property. + // Also, (for RT-21454) set the currently typed text as the value when focus + // is lost from the ComboBox textField.focusedProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue ov, Boolean t, Boolean hasFocus) { if (hasFocus) { comboBox.requestFocus(); } + + // RT-21454 starts here + if (! hasFocus) { + setTextFromTextFieldIntoComboBoxValue(); + } } }); @@ -287,6 +291,21 @@ } } + private void setTextFromTextFieldIntoComboBoxValue() { + StringConverter c = comboBox.getConverter(); + if (c == null) return; + + T oldValue = comboBox.getValue(); + T value = c.fromString(textField.getText()); + + if ((value == null && oldValue == null) || (value != null && value.equals(oldValue))) { + // no point updating values needlessly (as they are the same) + return; + } + + comboBox.setValue(value); + } + private int getSelectedIndex() { T value = comboBox.getValue(); int index = comboBox.getItems().indexOf(value);