TableView doesn’t commit values on focus lost event

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.

There is a hack shown in a SO thread, which seems to get the job done, although I haven’t tried it (yet).

Leave a Comment