有没有办法禁用Vaadins TreeTable组件中所选项目的蓝色突出显示(主要是treenodes)? 我使用一个标志来选择哪些项目不应该突出显示。 我已经在这几天工作了,但似乎没有任何工作按预期工作。 提前谢谢!
答案 0 :(得分:0)
由于树表扩展表,您可以在cell style generator中使用theme和一些与表相关的CSS 。上面的示例可能不是您正在寻找的100%,但它们应该让您开始并稍微调整一下,然后到达那里:
1)Java
signInWithPopup
2)主题/ CSS
public class TreetableWithoutSelectionBackground extends VerticalLayout {
public TreetableWithoutSelectionBackground() {
// standard tree table setup
TreeTable treeTable = new TreeTable();
treeTable.setSelectable(true);
treeTable.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
treeTable.setItemCaptionPropertyId("caption");
// cell style generator to decide whether the item should or should not have a background
// since we'll be using a bean item container, the itemIds will be the beans themselves so we can use those directly
treeTable.setCellStyleGenerator((source, itemId, propertyId) -> ((MyBean) itemId).shouldHaveBackground() ? null : "no-background");
// standard container
BeanItemContainer<MyBean> container = new BeanItemContainer<>(MyBean.class);
treeTable.setContainerDataSource(container);
// add some dummy data
Random random = new Random();
for (int i = 0; i < 10; i++) {
boolean shouldHaveBackground = random.nextBoolean();
container.addItem(new MyBean("Item - " + i + " [" + shouldHaveBackground + "]", shouldHaveBackground));
}
addComponent(treeTable);
}
// basic bean
public static class MyBean {
private String caption;
private boolean shouldHaveBackground;
public MyBean(String caption, boolean shouldHaveBackground) {
this.caption = caption;
this.shouldHaveBackground = shouldHaveBackground;
}
public String getCaption() {
return caption;
}
public void setCaption(String caption) {
this.caption = caption;
}
public boolean shouldHaveBackground() {
return shouldHaveBackground;
}
}
}
3)结果