1、表格要设置成可编辑。
2、对列进行如下设置。
列定义:
@FXML
private TableColumn<Hole, Boolean> id_colCheck;
列设置
id_colCheck.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Hole, Boolean>, ObservableValue<Boolean>>() {
@Override
public ObservableValue<Boolean> call(TableColumn.CellDataFeatures<Hole, Boolean> param) {
return param.getValue().checkProperty();
}
});
id_colCheck.setCellFactory(CheckBoxTableCell.forTableColumn(id_colCheck));
Hole类中字段的定义
BooleanProperty check = new SimpleBooleanProperty(false);
public boolean isCheck() {
return check.get();
}
public BooleanProperty checkProperty() {
return check;
}
public void setCheck(boolean check) {
this.check.set(check);
}