【发布时间】:2020-04-12 08:23:13
【问题描述】:
我在一列中有很长的字符串,我想在我的网格中将它们显示为多行单元格。 我正在使用 Vaadin 14 + Java,并尝试为特定列设置 CSS-Style Class:
Java-代码:
@CssImport("./styles/shared-styles.css")
public class RisikoGrid extends Grid<RisikoEntity> {
public RisikoGrid() {
setSizeFull();
// add the column to the grid
addColumn(Entity::getAttribute).setHeader("MyCol")
.setFlexGrow(10).setSortable(true).setKey("mycolumn");
// set CSS style class for the specific column
this.getColumnByKey("mycolumn").setClassNameGenerator(item -> {return "grid-mycol";});
}
}
CSS (shared-styles.css)
.grid-mycol{
background: red;
white-space: normal;
word-wrap: break-word;
}
虽然在我的网络浏览器 (chrome) 中使用检查器时确实看到了类名,但没有应用 css。
我需要进行哪些更改才能使其正常工作?
编辑:这就是我的样式的样子——我什至看不到背景:例如红色:
【问题讨论】:
-
grid-mycol 的样式如何?浏览器是否加载了shared-styles.css?
-
其他东西是从共享样式中加载的,并应用于我的 web 应用程序的其他地方。 “我的风格是什么样的”是什么意思?上面的css摘录?
-
哦,对不起。我没有在问题中看到它。 Chrome 中的计算样式是什么样的?你应该明白为什么没有应用样式
-
奇怪的是,背景:红色(以及我在 css 中设置的其他内容)不会出现在 css-inspector 中“样式”下的任何位置。我添加了一个截图
标签: java vaadin vaadin-grid vaadin14