一、表格要設置成可編輯。
二、對列進行以下設置。
列定義:
@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);}