0
請看下面的例子:TornadoFX如何將Node樣式(或styleClass)綁定到屬性?
class MainView : View("Example") {
val someBooleanProperty: SimpleBooleanProperty = SimpleBooleanProperty(true)
override val root = borderpane {
paddingAll = 20.0
center = button("Change bg color") {
action {
// let's assume that new someBooleanProperty value is updated
// from some API after button clicked
// so changing style of the borderpane in action block
// of the button is not the solution
someBooleanProperty.value = !someBooleanProperty.value
}
}
}
}
class Styles : Stylesheet() {
companion object {
val red by cssclass()
val green by cssclass()
}
init {
red { backgroundColor += Color.RED }
green { backgroundColor += Color.GREEN }
}
}
我怎麼能動態改變取決於someBooleanProperty
的borderpane
背景顏色(如紅色時true
和綠色時false
)?有沒有可能將CSS類綁定到一個屬性?是否有任何解決方案來做到這一點,而不使用CSS(意思是style
塊內)
完美,非常感謝你! – sk1ey