我正在尝试创建一个TreeTableView
并尝试将销售价值工厂设置为
@FXML
private TreeTableColumn<Good, Long> folderId;
这里:
folderId.setCellValueFactory((TreeTableColumn.CellDataFeatures<Good, Long> param) ->
new ReadOnlyLongWrapper(param.getValue().getValue().getFolderId()));
我得到这个带有下划线的红色标题中描述的错误。getFolderId
课堂上Good
是这样的:
public Long getFolderId() {
return folderId;
}
相同的方法适用于 String 或 Boolean 值,但会删除标题中提到的异常以及编译时的以下内容:
incompatible types: bad return type in lambda expression
javafx.beans.property.ReadOnlyLongWrapper cannot be converted to javafx.beans.value.ObservableValue<java.lang.Long>
如何获取ObservableValue<java.lang.Long>
而不是ReadOnlyLongWrapper
为什么这个异常只出现在 Long 值中?
这是整个方法:
goodsPane.setCenter(goodTreeTableView);
List<Good> goodAndFoldersList = goodsService.getGoods();
List<Good> goods = new ArrayList<Good>();
List<Good> roots = new ArrayList<Good>();
for (Good good: goodAndFoldersList){
if (good.isIs_folder()) {
roots.add(good);
}else {
goods.add(good);
}
}
TreeItem<Good> rootItem = new TreeItem<>();
for (Good root: roots){
Long folderId = root.getId();
TreeItem<Good> rootTreeItem = new TreeItem<>(root);
for (Good good: goods){
if (good.getFolderId() == folderId){
TreeItem<Good> goodTreeItem = new TreeItem<>(good);
rootTreeItem.getChildren().add(goodTreeItem);
}
}
rootItem.getChildren().add(rootTreeItem);
}
goodTreeTableView.setRoot(rootItem);
goodName.setCellValueFactory((TreeTableColumn.CellDataFeatures<Good, String> param) ->
new ReadOnlyStringWrapper(param.getValue().getValue().getName()));
folderId.setCellValueFactory((TreeTableColumn.CellDataFeatures<Good, Long> param) ->
new ReadOnlyLongWrapper(param.getValue().getValue().getFolderId()));
is_folder.setCellValueFactory((TreeTableColumn.CellDataFeatures<Good, Boolean> param) ->
new ReadOnlyBooleanWrapper(param.getValue().getValue().isIs_folder()));