Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save MainasuK/e5f18fac78ee8cdf552f25c757b483e7 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

How to convert Boolean to BooleanProperty ?

@Kuanlin-Chen
Copy link
Copy Markdown

I already figured this out.

@jmaruiz
Copy link
Copy Markdown

jmaruiz commented Oct 17, 2019

Thanks for this gist!

@VitorCosta15
Copy link
Copy Markdown

VitorCosta15 commented Nov 24, 2022

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

@xkkpafi
Copy link
Copy Markdown

xkkpafi commented Feb 26, 2026

Syntax error: booleanColumn.setCellValueFactory(cellData -> {T cellValue = cellData.getValue(); Cannot find symbol class T. Please correct.

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