Как настроить прослушиватель событий для CheckBoxTableCell, который изначально является столбцом BooleanProperty, чтобы ⇐ JAVA
-
Anonymous
Как настроить прослушиватель событий для CheckBoxTableCell, который изначально является столбцом BooleanProperty, чтобы
I have an eventtable TableView, and I have a StudentGuardian class that has:
private SimpleStringProperty studentName; private BooleanProperty hasGuardian; private SimpleStringProperty guardianName; In my Controller, I've set it up so that the BooleanProperty is turned into a checkbox, like this:
public void setupCheckbox(){ hasGuardianTableColumn.setCellValueFactory(c -> new SimpleBooleanProperty(c.getValue().getHasGuardian())); hasGuardianTableColumn.setCellFactory(tc -> new CheckBoxTableCell()); eventtable.setEditable(true); } It actually works fine, the checkbox turns up and I can check/uncheck it. But it's not actually updating the value of the BooleanProperty when the user clicks the checkbox.
I tried to do this on the same method as the setupCheckbox:
hasGuardianTableColumn.setCellFactory(CheckBoxTableCell.forTableColumn(hasGuardianTableColumn)); hasGuardianTableColumn.setOnEditCommit( (TableColumn.CellEditEvent t) -> (t.getTableView().getItems().get( t.getTablePosition().getRow())).setHasGuardian(t.getNewValue()) ); But it's not working, and I know that since it's not an event listener. I'm really not sure how I'd set up an event listener for the CheckBox since it seems to only be enclosed in that method so I don't know how to reference it. I found this thread, but again, I can't reference the new CheckBoxTableCell. I'm also wondering if I should put it in the @Override, or maybe I'm doing it wrong with the way to set it up (or I'm asking the wrong question). Anything helps.
Источник: https://stackoverflow.com/questions/781 ... lly-a-bool
I have an eventtable TableView, and I have a StudentGuardian class that has:
private SimpleStringProperty studentName; private BooleanProperty hasGuardian; private SimpleStringProperty guardianName; In my Controller, I've set it up so that the BooleanProperty is turned into a checkbox, like this:
public void setupCheckbox(){ hasGuardianTableColumn.setCellValueFactory(c -> new SimpleBooleanProperty(c.getValue().getHasGuardian())); hasGuardianTableColumn.setCellFactory(tc -> new CheckBoxTableCell()); eventtable.setEditable(true); } It actually works fine, the checkbox turns up and I can check/uncheck it. But it's not actually updating the value of the BooleanProperty when the user clicks the checkbox.
I tried to do this on the same method as the setupCheckbox:
hasGuardianTableColumn.setCellFactory(CheckBoxTableCell.forTableColumn(hasGuardianTableColumn)); hasGuardianTableColumn.setOnEditCommit( (TableColumn.CellEditEvent t) -> (t.getTableView().getItems().get( t.getTablePosition().getRow())).setHasGuardian(t.getNewValue()) ); But it's not working, and I know that since it's not an event listener. I'm really not sure how I'd set up an event listener for the CheckBox since it seems to only be enclosed in that method so I don't know how to reference it. I found this thread, but again, I can't reference the new CheckBoxTableCell. I'm also wondering if I should put it in the @Override, or maybe I'm doing it wrong with the way to set it up (or I'm asking the wrong question). Anything helps.
Источник: https://stackoverflow.com/questions/781 ... lly-a-bool
Мобильная версия