简体   繁体   中英

cannot set colors css tornadofx

I am just playing with examples of TornadoFX, but I cannot reproduce the following https://github.com/edvin/tornadofx/wiki/Type-Safe-CSS , more precisely:

backgroundColor += hoverColor

Doesn't compile for me, it says type mismatch, required Paint, found CSSRule Neither can I set the borderColor +=box(dangerColor) , I also have a type mismatch图片类型不匹配

Your imports are wrong, try using the

import tornadofx.*

statement. Currently, you are using tornadofx.Stylesheet.Companion.box function, instead of the box function from CSSKt.class .

I just tested your exact code and it compiles and works. Either you're using an outdated version of TornadoFX or you have some other error in your file that confuses IDEA to give you the wrong error message. Try for yourself with this exact snippet and you'll see that it compiles:

class Styles : Stylesheet() {
    companion object {
        val dangerColor = c("#a94442")
        val hoverColor = c("#d49942")
    }

    init {
        root {
            button {
                backgroundColor += Color.GRAY
                borderWidth += box(5.px)
                borderColor += box(dangerColor)
                and(hover) {
                    backgroundColor += hoverColor
                }
            }
        }
    }
}

On another note: Why do you wrap everything in root ? There should be no need for that.

you can use two builtin functions

  1. c() //pass color string and opacity as parameters
  2. multi() // pass string color

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