我建模了一个TreeView<Playlist>
这样的节点,有孩子的节点有一个文件夹图标作为图形,而其他节点有一个播放列表图标。样式几乎可以工作,但是在展开/折叠节点时,图形图标会损坏。
单击节点时,它始终显示正确的样式,但在展开/折叠或添加新节点时,TreeView
行为如下:
这是代码的一部分,其中定义TreeCell
了TreeView
public class PlaylistTreeView extends TreeView<Playlist> {
public PlaylistTreeView() {
...
setShowRoot(false);
setCellFactory(treeView -> new PlaylistTreeCell());
...
}
private class PlaylistTreeCell extends TreeCell<Playlist> {
@Override
public void updateItem(Playlist p, boolean empty) {
super.updateItem(p, empty);
if(p == null || empty) {
textProperty().unbind();
setText("");
setGraphic(null);
}
else {
if(p.isFolder())
setId("playlist-folder-tree-cell");
else
setId("playlist-tree-cell");
textProperty().bind(p.nameProperty());
}
}
}
}
这些是唯一影响这些组件的样式css
:
.tree-cell, .list-cell {
-fx-background-color: rgb(243, 243, 243);
}
#playlist-tree-cell {
-fx-graphic: url('../icons/playlist-black-icon.png');
}
#playlist-tree-cell:selected {
-fx-graphic: url('../icons/playlist-white-icon.png');
}
#playlist-folder-tree-cell {
-fx-graphic: url('../icons/playlist-folder-black-icon.png');
}
#playlist-folder-tree-cell:selected {
-fx-graphic: url('../icons/playlist-folder-white-icon.png');
}
.list-cell:selected, .tree-cell:selected {
-fx-background-color: black;
-fx-text-fill: white;
}
我在这里想念什么?