When pressing enter leave the editing mode and commit the new value.

Also reset the value when cancel the edit mode.
This commit is contained in:
2022-10-22 21:21:54 +02:00
parent 0db16c0328
commit 1b39c9a08e

View File

@@ -65,8 +65,8 @@ public class EditableValidationCell extends TableCell<CSVRow, CSVValue> {
@Override @Override
public void cancelEdit() { public void cancelEdit() {
super.cancelEdit();
setText(getItem().getValue()); setText(getItem().getValue());
super.cancelEdit();
setContentDisplay(ContentDisplay.TEXT_ONLY); setContentDisplay(ContentDisplay.TEXT_ONLY);
} }
@@ -113,16 +113,11 @@ public class EditableValidationCell extends TableCell<CSVRow, CSVValue> {
textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2); textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
textField.setOnKeyPressed(t -> { textField.setOnKeyPressed(t -> {
if (t.getCode() == KeyCode.ENTER) { if (t.getCode() == KeyCode.ENTER) {
commitEdit(textField.getValue()); runLater(() -> commitEdit(textField.getValue()));
} else if (t.getCode() == KeyCode.ESCAPE) { } else if (t.getCode() == KeyCode.ESCAPE) {
cancelEdit(); cancelEdit();
} }
}); });
textField.focusedProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue && textField != null) {
commitEdit(textField.getValue());
}
});
} }
private static class ValueTextField extends TextField { private static class ValueTextField extends TextField {