Generate a tableview with a column containing a checkboxes and add listners to those checkboxes

泪湿孤枕 提交于 2019-12-06 12:04:44

JavaFX is all about separating Model and View.

Your CheckBoxTableCell is the View and the ObservableValue<Boolean> is the Model.

We do not see your code, but somewhere you have to initialize your CheckBoxTableCellwith a BooleanProperty of some sorts. This property gets toggled by the CheckBox in the rendered TableView.

So you just have to register listener(s) to this / these property / properties.


Edit:

You should change your TableColumn from

private TableColumn<Job, CheckBox> checkBoxTableColumn;

to

private TableColumn<Job, Boolean> checkBoxTableColumn;

Further you will need a BooleanProperty in your Job class. For example:

private final BooleanProperty test = new SimpleStringProperty(this, "test", false);

public BooleanProperty testProperty() {
    return test;
}

Now back to your TableView:

checkBoxTableColumn.setCellFactory(CheckBoxTableCell.forTableColumn(checkBoxTableColumn.setCellFactory());
checkBoxTableColumn.setCellValueFactory(c -> c.getValue().testProperty());
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!