我认为这是因为只有当TreeCell的项目被替换的updateItem方法被调用,而不是改性。您需要的是一种通知TreeCell实例其项目属性已更改的方法。
例如,尝试将textProperty绑定到模型对象的所需属性,而不是使用setText方法修改您的treecell的文本。当然,您将需要更新您的模型以使用JavaFX Property和绑定 另一种解决方案可能是使用PropertyChangeListener,旧样式。
如果你想要的例子,我可以尝试提供一个。
编辑:一个小例子。我修改了Episode叶子的文字。当然,您需要将EpsiodeDetails类的插曲和标题属性移动到javafx样式的属性。
@Override
protected void updateItem(ITVShowItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
if (item instanceof Show) {
//nothing
} else if (item instanceof Season) {
Season season = (Season) item;
setText("Season " + season.getSeason());
} else if (item instanceof Episode) {
Episode episode = (Episode) item;
this.textProperty().bind(Bindings.concat(episode.getDetails().episodeProperty(), " - ", episode.getDetails().titleProperty()));
//setText(episode.getDetails().getEpisode() + " - " + episode.getDetails().getTitle());
}
}
}
Bindings.concat方法真的很棒。感谢您的宝贵意见。 – Muki 2012-07-25 15:52:39
你的欢迎:) – Teocali 2012-07-25 19:34:24