Reputation: 1747
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.
The following code (using inline CSS) works:
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.
The CSS class is a literaly copy-paste of the inline 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?
Upvotes: 2
Views: 274
Reputation: 841
Try adding this to your init section of the view/fragment containing your listview:
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.
Upvotes: 1