简体   繁体   中英

TornadoFX addClass does not add CSS

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM