I have a tableview with some input controls inside its tablecells which are bind to a model's properties. The problem is that with any change the user mades in textfields, they lose the focus when doing the binding.
tblcNombre.setCellValueFactory(new PropertyValueFactory<Responsable, String>("nombre"));
tblcNombre.setCellFactory(col -> {
TableCell<Responsable, String> cell = new TableCell<Responsable, String>(){
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if(empty) {
setText("");
setGraphic(null);
}else {
TextField tf = new TextField();
tf.textProperty().bindBidirectional(getTableRow().getItem().nombreProperty());
tf.setText(item);
setGraphic(tf);
}
}
};
return cell;
});
Any idea on how to solve it? Thank you!
Edit: I think it happens becasue when user changes textfield text, the cell is repainted, so updateItem is called again, and it creates a new textfield with a new binding. But I can't find a solution for it