我有改变细胞的图标,下面的代码的问题:JavaFX的更改单元格图标
TableColumn typeCol = new TableColumn("Account Type");
typeCol.setCellFactory(new Callback<TableColumn<Account, String>, TableCell<Account, String>>() {
@Override
public TableCell<Account, String> call(TableColumn<Account, String> param) {
TableCell<Account,String> cell = new TableCell<Account, String>(){
@Override
public void updateItem(Account item, boolean empty){
if (item != null){
VBox vb = new VBox();
vb.setAlignment(Pos.CENTER);
ImageView imgVw = new ImageView(item.getTypeIcon());
imgVw.setFitHeight(10);
imgVw.setFitWidth(10);
vb.getChildren().addAll(imgVw);
setGraphic(vb);
}
}
};
return cell;
}
});
typeCol.setMinWidth(100);
typeCol.setCellValueFactory(
new PropertyValueFactory<Account, String>("type"));
这里的问题是,由于某种原因,我得到的连接的“方法不覆盖或执行错误一种形式超类型的方法“。任何idaes?
如何访问我的对象在updateItem方法中的方法? – uksz
@uksz:看我的编辑。基本上,'cellValueFactory'选择要使用的项目的一部分,'cellFactory'返回的单元格显示该数据(在本例中为图像)。 – fabian