I got curious and did some background research.
You are facing the problem of a well-known bug in the JavaFX.
Background
When you call commitEdit(textField.getText())
, the first thing it does is to check the value of isEditing()
and returns if the value is false
, without committing.
public void commitEdit(T newValue) {
if (! isEditing()) return;
... // Rest of the things
}
Why does it return false?
As you have probably found out, as soon as you press TAB
or ENTER
to change your selection, cancelEdit()
is called which sets the TableCell.isEditing()
to false. By the time the commitEdit()
inside textField’s focus property listener is called, isEditing()
is already returning false.
Solutions / Hacks
There have been on going discussion on the Topic in JavaFX community. People in there have posted hacks, which you are most welcome to look at.
- TableView, TreeView, ListView – Clicking outside of the edited cell, node, or entry should commit the value
- TableCell – commit on focus lost not possible in every case
There is a hack shown in a SO thread, which seems to get the job done, although I haven’t tried it (yet).