ScalaFX。 Label - 如何绑定IntegerProperty?

时间:2017-12-11 11:43:04

标签: binding scalafx

我有一个简单的表格,例如:

object ViewModel {
  //Some mutable integer property. I want to keep it as IntegerProperty, not StringProperty
  val intProp = IntegerProperty(10)

  intProp.value = 15
}

一个简单的例子ViewModel:

IntegerProperty

如何将我的StringProperty绑定到我的标签,预计{{1}}?

1 个答案:

答案 0 :(得分:2)

已编辑:我忘了.asString。卫生署!

您可以按如下方式绑定属性:

Main.scala

object Main extends JFXApp {
  stage = new PrimaryStage() {
    title = "My Form"
    scene = new Scene {

      // Bind label to int property as a string.
      root = new Label {
        text <== ViewModel.intProp.asString
      }
    }
  }
}

ViewModel.scala

object ViewModel {
  val intProp = IntegerProperty(10)

  intProp.value = 15
}