gpt4 book ai didi

css - 删除使用伪类添加的 JavaFX TreeCell 格式

转载 作者:太空宇宙 更新时间:2023-11-04 08:26:24 25 4
gpt4 key购买 nike

我正在使用 PseudoClass 根据树单元格中数据给出的条件更改 JavaFx TreeCell 的格式。以下代码有效:

public class EmfTreeCellImpl extends TreeCell<EmfTreeNode> {

PseudoClass AMBIGUOUS_FEATURE = PseudoClass.getPseudoClass("ambiguous-feature");

public EmfTreeCellImpl() {
}

@Override
protected void updateItem(EmfTreeNode item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
setGraphic(null);
return;
}
setText(item.getLabel());
setEditable(false);
if (item instanceof EmfTreeNode.SingleAttributeNode) {
EmfTreeNode.SingleAttributeNode san = (EmfTreeNode.SingleAttributeNode) item;
//pseudoClassStateChanged(AMBIGUOUS_FEATURE, san.isAmbiguous());
pseudoClassStateChanged(AMBIGUOUS_FEATURE, san.isAmbiguous());
}
}
}

单元格正确突出显示。问题是突出显示在 GUI 的特定树单元格中“持续存在”。也就是说,如果我折叠或展开其他 Twig ,突出显示将保持“原位”,突出显示不符合条件的其他单元格。我认为 setGraphic(null) 会删除格式。

为了解决这个问题,我在 updateItem 中添加了一行以清除格式:

if (empty || item == null) {
setText(null);
setGraphic(null);
pseudoClassStateChanged(AMBIGUOUS_FEATURE, false);
return;
}

但不知何故,我觉得我应该只从已格式化的格式中删除格式或使用更“全局”的清除格式。

最佳答案

如评论中所述,答案中提出的解决方案本身是完全有效的,但是更简洁的处理方式可能是使用内置的 filled Cell 伪类自动应用于任何非空单元格:

:filled:ambiguous-feature { 
/* css-styling of non-empty ambiguous cells */
}

关于css - 删除使用伪类添加的 JavaFX TreeCell 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45139344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com