[英]TornadoFX addClass does not add CSS
TLDR; TLDR; When trying to change the background color of a listview
using inline CSS with style { ... }
it works but addClass
using a copy-pasted CSS does nothing.当尝试使用style { ... }
内联 CSS 更改listview
的背景颜色时,它可以工作,但使用复制粘贴的 CSS 的addClass
什么也不做。
The following code (using inline CSS) works:以下代码(使用内联 CSS)有效:
listview(monsterController.monsters) {
vgrow = Priority.ALWAYS
cellFormat {
// addClass(StatBlockStyles.monsterListCell)
style {
backgroundColor += Color.color(253.0 / 255.0, 241.0 / 255.0, 220.0 / 255.0)
}
graphic = label(it.name)
}
But if I comment the style { ... }
and uncomment the addClass(...)
it seems to have no effect.但是如果我注释style { ... }
并取消注释addClass(...)
它似乎没有效果。
The CSS class is a literaly copy-paste of the inline CSS: CSS 类是内联 CSS 的字面复制粘贴:
import javafx.scene.paint.Color
import tornadofx.*
class StatBlockStyles: Stylesheet() {
companion object {
val monsterListCell by cssclass()
}
init {
monsterListCell {
backgroundColor += Color.color(253.0 / 255.0, 241.0 / 255.0, 220.0 / 255.0)
}
}
}
Why does this happen and what should I do to be able to actually separate the styling from the rest of the code?为什么会发生这种情况,我应该怎么做才能真正将样式与代码的其余部分分开?
Try adding this to your init section of the view/fragment containing your listview:尝试将其添加到包含列表视图的视图/片段的 init 部分:
init {
importStylesheet(StatBlockStyles::class)
}
Note: You only need to use the import function once.注意:您只需要使用一次导入功能。 The styling will remain for the rest of the program, even in other windows/views/fragments.样式将保留在程序的其余部分,即使在其他窗口/视图/片段中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.