【发布时间】:2018-01-26 05:10:24
【问题描述】:
当从组合框项目中选择时,tableview 刷新正常。
ObservableList<Specie> species = FXCollections.observableArrayList();
//the tableview items depends on genderComboBox selected item
livingBeingTableView.itemsProperty().bind(Bindings.createObjectBinding(() -> {
Gender gender = genderComboBox.getValue();
if (gender == null) {
return FXCollections.observableArrayList();
} else {
int id = gender.getId();
//seachSpeciesIdGender(int id) find the species with the id associated
species = SpecieDAO.searchSpeciesIdGender(id);
return species;
}
}, genderComboBox.valueProperty()));
问题是。插入新项目并将其添加到 tableview 时
private void handleNewSpecie() {
Specie tempSpecie = new Specie();
boolean okClicked = main.showSpecieEditDialog(tempSpecie);
if (okClicked) {
SpecieDAO.insertSpecie(tempSpecie.getCommonName(), tempSpecie.getScientName(),
genderComboBox.getValue().getId(), 0, 0,
0, 0, 0);
int id = genderComboBox.getValue().getId();
species = SpecieDAO.searchSpeciesIdGender(id)
livingBeingTableView.setItems(species);
}
}
无法设置绑定值
Caused by: java.lang.RuntimeException: TableView.items : A bound value cannot be set.
at javafx.base/javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:143)
at javafx.controls/javafx.scene.control.TableView.setItems(TableView.java:862)
at cu.edu.cujae.guatini.controller.MainController.handleNewSpecie(MainController.java:213)
... 62 more
是否可以将带有绑定 tableview 的项目插入到组合框?我究竟做错了什么?感谢和对不起我的英语
【问题讨论】: