javafx listview和treeview控件没有被正确重绘

我试图把元素放在一个ListView和TreeView与javafx,但两个控件都不会刷新它们的内容。 我正在使用obvservable列表来控制项目,每次我删除一个项目时,listview或treeview从数据源中删除它。 但是视图不更新。 我仍然看到所有的项目。 唯一的区别是,删除的项目不能再被选中。 例如链接2显示了拼合的项目列表。 图片1显示了它们拼合之前的项目。 项目被折叠,但旧的条目仍然可见。 有没有人知道这个问题的解决scheme。 谢谢大家帮助我

链接1: treeview不折叠链接2: treeview被折叠,但不更新旧的视图

这是我用来显示一个列表视图的自定义单元格工厂:

public ListCell<T> call(final ListView<T> param) { ListCell<T> cell = new ListCell<T>(){ @Override protected void updateItem(final T persistentObject, final boolean empty) { super.updateItem(persistentObject, empty); if(persistentObject instanceof POProcessStep){ POProcessStep poProcessStep = (POProcessStep) persistentObject; if (persistentObject != null) { super.setText(poProcessStep.getId() + " - " + poProcessStep.getTitle()); } }else if(persistentObject instanceof POProcess){ POProcess poProcess = (POProcess) persistentObject; if (persistentObject != null) { super.setText(poProcess.getId() + " - " + poProcess.getTitle()); } }else if(persistentObject instanceof POCategory){ POCategory poCategory = (POCategory) persistentObject; if(persistentObject != null){ super.setText(poCategory.getId() + " - " + poCategory.getTitle()); } }else if(persistentObject instanceof String){ if(persistentObject != null){ super.setText(String.valueOf(persistentObject)); } } super.setGraphic(null); } }; return cell; } 

您的单元工厂的updateItem(...)需要处理单元格为空的情况。 当项目项目被删除(或者由于TreeView一个节点被折叠而变为空白)并且以前显示一个项目的单元格被重用为空单元格时,

 public ListCell<T> call(final ListView<T> param) { ListCell<T> cell = new ListCell<T>(){ @Override protected void updateItem(final T persistentObject, final boolean empty) { super.updateItem(persistentObject, empty); if (empty) { setText(null); setGraphic(null); } else { // ... rest of your code. } } } return cell ; }