I have an observable list whose elements are shown in a table, one of whose columns is a CheckBox
that can be modified by the user by clicking on them with the mouse. I want that when these CheckBox
change I am notified to store those changes in a database.
The CheckBox
column is this:
TableColumn<Person, Boolean> acceptedCol = new TableColumn<>("Accepted");
acceptedCol.setCellValueFactory(new PropertyValueFactory<>("accepted"));
acceptedCol.setCellFactory((TableColumn<Person, Boolean> p) -> {
CheckBoxTableCell<Person, Boolean> cell = new CheckBoxTableCell<>();
cell.getStyleClass().add("okGrasa");
cell.setAlignment(Pos.CENTER);
return cell;
});
The list consists of objects of class Person
:
public class Person {
private String name;
private BooleanProperty accepted;
public Person(String name, boolean accepted) {
this.name = name;
this.accepted = new SimpleBooleanProperty(accepted);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BooleanProperty acceptedProperty() {
return accepted;
}
public boolean isAccepted() {
return acceptedProperty().get();
}
}
I have filled the table with the list:
ObservableList<Person> list = getPersonList();
TableView<Person> table = new TableView<>();
table.setItems(list);
And I've tried this:
list.addListener(new ListChangeListener() {
@Override
public void onChanged(ListChangeListener.Change c) {
System.out.println ("Ha habido un cambio");
}
});
But it only detects changes in the observable list but does not detect the editing of each one of the elements that make it up. Why?