JavaFX2 in Scala: add the ChangeListener for a StringProperty

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
  val rateColumnTypeProperty = new SimpleStringProperty(rateColumnType)
  val columnTypeDescriptionProperty = new SimpleStringProperty

  rateColumnTypeProperty.addListener(new ChangeListener[String] {
    override def changed(o: ObservableValue[_ <: String], oldVal: String, newVal: String): Unit = {

      val colTypeOption = CodeTableLoader.codeTableRateCol.get(newVal)

      val desc =
        if (colTypeOption.isDefined) {
          colTypeOption.get.description
        } else {
          "N/A"
        }

      columnTypeDescriptionProperty.set(desc)
    }
  })
Advertisements