我不知道如何在JFXTreeTableView中添加图像,因为当我将变量类型设置为ImageView时,出现一个错误,我应该给它String数据。这是我的类和构造函数:
class TeamsInnerClass extends RecursiveTreeObject<TeamsInnerClass> {
ImageView icon;
SimpleStringProperty teamName;
...
public TeamsInnerClass(ImageView icon, String teamName) {
this.icon = icon;
this.teamName = new SimpleStringProperty(teamName);
}
}
这是控制器:
JFXTreeTableColumn<TeamsInnerClass, ImageView> icon = new JFXTreeTableColumn<>();
icon.setPrefWidth(100);
icon.setCellValueFactory(param -> param.getValue().getValue().icon);
JFXTreeTableColumn<TeamsInnerClass, String> teamName = new JFXTreeTableColumn<>("Teams");
teamName.setPrefWidth(100);
teamName.setCellValueFactory(param -> param.getValue().getValue().teamName);
...
以及构造函数生成的数据:
ObservableList<TeamsInnerClass> teamsInnerClass = FXCollections.observableArrayList();
teamsInnerClass.add(new TeamsInnerClass(new ImageView(new Image("League/backs/background2.jpg")), "Real"));
final TreeItem<TeamsInnerClass> root = new RecursiveTreeItem<>(teamsInnerClass, RecursiveTreeObject::getChildren);
scoresTable.getColumns().addAll(icon, teamName);
scoresTable.setRoot(root);
scoresTable.setShowRoot(false);
和我得到的错误: