Answer the question
In order to leave comments, you need to log in
How to get ID on click on checkbox in JavaFX?
Hello. I'm having trouble getting event data. I need that when clicking on the checkbox, which are displayed through the CheckBoxTableCell in the TableView column, I could get true or false. Now only one checkbox works for me, which selects all the others and displays the record IDs from my model in the console. Here is what I have:
Controller
@FXML
private void initialize() {
selectedColumn.setCellFactory(CheckBoxTableCell.forTableColumn(selectedColumn));
select_all.selectedProperty().addListener((observable, oldValue, newValue) -> {
for(Person person : personTable.getItems()) {
person.setSelected(newValue);
if(newValue == true) {
int count = personTable.getItems().size();
getDeleteAllPersBtn().setText("Delete (" + count + ")");
personTable.getSelectionModel().select(person.getPersonId());
System.out.println(person.getPersonId());
} else {
personTable.getSelectionModel().clearSelection(person.getPersonId());
getDeleteAllPersBtn().setText("Delete");
}
}
getDeleteAllPersBtn().setDisable(!select_all.isSelected());
});
}
public class Person {
private SimpleBooleanProperty selected;
private IntegerProperty id;
//Constructor
public Person() {
this.selected = new SimpleBooleanProperty(false);
this.id = new SimpleIntegerProperty();
}
//selected
public BooleanProperty selectedProperty() {
return selected;
}
public boolean getSelected() {
return selected.get();
}
public void setSelected(boolean selected) {
this.selected.set(selected);
}
}
<TableColumn fx:id="selectedColumn" prefWidth="50.0" style="-fx-alignment: CENTER;">
<graphic>
<CheckBox fx:id="select_all" mnemonicParsing="false" />
</graphic>
<cellValueFactory>
<PropertyValueFactory property="selected" />
</cellValueFactory>
</TableColumn>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question