我想在tableview的单元格的值为空时更改tableview的单元格背景色。你可以帮帮我吗?谢谢。 下面,我的源代码的概述,但它不起作用。如何动态地改变tableview的单元格背景
public class Cell extends TextFieldTableCell<Itemtest, String>{
public Cell(StringConverter<String> str){
super(str);
this.itemProperty().addListener((obs, oldValue, newValue)->{
if(newValue.isEmpty())
this.setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)));
});
}
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(empty ? null : getString());
setGraphic(null);
}
private String getString(){
return getItem() == null ? "" : getItem().toString();
}
}
您不需要为此执行单元实施;你可以完全用CSS做 –