Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MainasuK/e5f18fac78ee8cdf552f25c757b483e7 to your computer and use it in GitHub Desktop.
Save MainasuK/e5f18fac78ee8cdf552f25c757b483e7 to your computer and use it in GitHub Desktop.
Add checkbox cell to tableView - JavaFX 8 with lambda
TableView<T> tableView;
TableColumn<T, Boolean> booleanColumn;
private void setupTableView() {
tableView.setEditable(true);
}
private void setupTableViewColumn() {
booleanColumn.setCellFactory(column -> new CheckBoxTableCell<>());
booleanColumn.setCellValueFactory(cellData -> {
T cellValue = cellData.getValue();
BooleanProperty property = cellValue.choosedProperty();
// Add listener to handler change
property.addListener((observable, oldValue, newValue) -> cellValue.setChoosed(newValue));
return property;
});
}
@Kuanlin-Chen
Copy link

How to convert Boolean to BooleanProperty ?

@Kuanlin-Chen
Copy link

I already figured this out.

@jmaruiz
Copy link

jmaruiz commented Oct 17, 2019

Thanks for this gist!

@VitorCosta15
Copy link

VitorCosta15 commented Nov 24, 2022

Thank you so much!!! Especially for the details on the setCellValueFactory!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment