[英]How to use CheckBoxListCell in ScalaFX?
我正在嘗試使用scalaFX列出checkBox。 通過一些研究,我發現CheckBoxListCell組件可以解決此問題。 但是我沒有發現scalaFX的一個很好的例子(只有javaFX)。 請任何幫助? 謝謝
這是一個完整的ScalaFX示例:
package scalafx.controls
import scala.language.implicitConversions
import scalafx.Includes._
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.beans.property.BooleanProperty
import scalafx.collections.ObservableBuffer
import scalafx.scene.Scene
import scalafx.scene.control.cell.CheckBoxListCell
import scalafx.scene.control.{Button, ListView}
import scalafx.scene.layout.VBox
object CheckBoxListCellDemo extends JFXApp {
class Item(initialSelection: Boolean, val name: String) {
val selected = BooleanProperty(initialSelection)
override def toString = name
}
val data = ObservableBuffer[Item](
(1 to 10).map { i => new Item(i % 2 == 0, s"Item $i") }
)
stage = new PrimaryStage {
scene = new Scene {
title = "CheckBoxListCell Demo"
root = new VBox {
children = Seq(
new ListView[Item] {
prefHeight=250
items = data
cellFactory = CheckBoxListCell.forListView(_.selected)
},
new Button("Print State ") {
onAction = handle {
println("-------------")
println(data.map(d => d.name + ": " + d.selected()).mkString("\n"))
}
}
)
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.