From 1b39c9a08e641bc91ff97028ddff7e6742441d08 Mon Sep 17 00:00:00 2001 From: Andreas Billmann Date: Sat, 22 Oct 2022 21:21:54 +0200 Subject: [PATCH] When pressing enter leave the editing mode and commit the new value. Also reset the value when cancel the edit mode. --- .../javafx/smartcsv/fx/table/EditableValidationCell.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/ninja/javafx/smartcsv/fx/table/EditableValidationCell.java b/src/main/java/ninja/javafx/smartcsv/fx/table/EditableValidationCell.java index 8892ae1..4657bbc 100644 --- a/src/main/java/ninja/javafx/smartcsv/fx/table/EditableValidationCell.java +++ b/src/main/java/ninja/javafx/smartcsv/fx/table/EditableValidationCell.java @@ -65,8 +65,8 @@ public class EditableValidationCell extends TableCell { @Override public void cancelEdit() { - super.cancelEdit(); setText(getItem().getValue()); + super.cancelEdit(); setContentDisplay(ContentDisplay.TEXT_ONLY); } @@ -113,16 +113,11 @@ public class EditableValidationCell extends TableCell { textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2); textField.setOnKeyPressed(t -> { if (t.getCode() == KeyCode.ENTER) { - commitEdit(textField.getValue()); + runLater(() -> commitEdit(textField.getValue())); } else if (t.getCode() == KeyCode.ESCAPE) { cancelEdit(); } }); - textField.focusedProperty().addListener((observable, oldValue, newValue) -> { - if (!newValue && textField != null) { - commitEdit(textField.getValue()); - } - }); } private static class ValueTextField extends TextField {