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