0

Where I used to be able to get edits in a textfield in a table view to commit when the user changed focus outside the cell (e.g., by clicking on another cell, a button, etc.), this doesn't work any longer. Other than installing a Java update (1.8.0_51) I don't know what could have caused this…

Like all similar samples on the internet, the code I use is a simple changeListener to the focused property of the textfield:

textField.focusedProperty().addListener(
    (ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) -> {
        if (!newVal) {
            commitEdit(textField.getText());
        }
    });

While the code still gets properly executed, the commit doesn't work. I did some digging and found that prior to the change listener being fired, the cell editing mode has already been turned off (cancelEdit has been fired). As a result the commitEdit doesn't do anything any longer.

To illustrate the (changed) behaviour you can basically use any sample code, for instance Hasan Kara's sample on GitHub: https://gist.github.com/haisi/0a82e17daf586c9bab52 (line 217 adds the focused property change listener)

Any ideas how to fix this???

While How to enable commit on focusLost for TableView/TreeTableView? indeed gives a possible fixes, these fixes hacks, very likely not to work when Java is updated. I need a working solution that is ready for production. I can't imagine there is no working solution possible without reverting to hacks (as many have indicated already, JavaFX not committing when you change focus on a cell is very bad behaviour indeed.) Furthermore, even Oracle's own examples make use of the focusChange listener, so there is clearly something broken in the more recent Java versions

Community
  • 1
  • 1
Hayo Baan
  • 594
  • 5
  • 17
  • @kleopatra, thanks for your reference to the other answer! However, while indicating a potential fix, as indicated, it is a hack, likely not to work with updates of JavaFX so it doesn't really help me :worried: – Hayo Baan Aug 05 '15 at 10:37
  • agreed, all we have are hacks (which might not even work with the current version of fx) - as long as the bug referenced in the other QA isn't fixed, there is no clean solution, unfortunately .. – kleopatra Aug 05 '15 at 10:44

0 Answers0