0

I follow this example to use CheckBoxTableCell in TableView:

JavaFX: CheckBoxTableCell get ActionEvent when user check a checkBox

I have table in my project like this:

TableView with three TableColums: icon/name, primary and secondary headers I tried this code to validate (in the same row) if primary checkbox or secondary checkbox is selected, the other one unselect. But code doesnt work:

primaryTableColumn.setCellFactory(CheckBoxTableCell.forTableColumn(i -> {
    Diet diet = diets.get(i);
    if (diet.isPrimary()) {
        diet.setSecondary(false);
    }
    return diet.primaryProperty();
}));

secondaryTableColumn.setCellFactory(CheckBoxTableCell.forTableColumn(i -> {
    Diet diet = diets.get(i);
    if (diet.isSecondary()) {
        diet.setPrimary(false);
    }
    return diet.secondaryProperty();
}));

How can i code in order to uncheck one checkbox if other one in same row is checked (preferably using bindings)? thanks and sorry for my english

  • I don't think this behavior should be handled by the view. If `primary` and `secondary` are mutually exclusive then it should be handled by `Diet` itself or possibly some service class if you have one. – Slaw Sep 07 '18 at 22:05
  • Thanks @Slaw, i code addListener in `Diet` and now works. – Alberto Amat Alvarez Sep 10 '18 at 16:41

0 Answers0