The main problem with your approach is the use of CheckBoxTableCell: The cell is a heavily used rendering machine. If you try to add a state, such as a CheckBox variable, you have problems.
The simplest solution to the problem is to select the check box every time. The following code provides a working column for the flag:
public static class Member { private StringProperty myName; private BooleanProperty myCheck; public Member(String name, boolean checked) { myName = new SimpleStringProperty(name); myCheck = new SimpleBooleanProperty(checked); } public StringProperty nameProperty() { return myName; } public BooleanProperty checkProperty() { return myCheck; } } VBox testTable6(VBox box) {
Since a bidirectional property binding is weak binding, carbide assembly will work properly even if you cannot unbind explicitly.
An unverified cast on BooleanProperty is not a very good style, anyway, sorry. Think about accessing an entire object using:
... Member member = table.getItems().get(getIndex()); box.setSelected(member.checkProperty().get()); box.selectedProperty().bindBidirectional(member.checkProperty()); ....
By the way: birdeirectional binding will NOT set the selected property at this moment, only if it is changed later! therefore explicit purpose:
box.setSelected(member.checkProperty().get());
is a must here.
source share