I am trying to make a list of checkBox with scalaFX. With some research i found the CheckBoxListCell Component to resolve this problem. But i didn't find a a good example with scalaFX ( there is only with javaFX). Please any help ? Thanx
Asked
Active
Viewed 640 times
1 Answers
0
Here is a complete ScalaFX example:
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"))
}
}
)
}
}
}
}

Jarek
- 1,513
- 9
- 16
-
i tried this code but i have an error " Reassignment to val " maybe it caused by val name ! – Achref May 07 '15 at 10:07
-
`val` means constant in Scala. "Reassignment to val" means attempt to assign to a constant. I double checked the code, it compiles and runs fine. Did you modify it? What is the exact error message and what line in code it points to? What version of ScalaFX are you using? – Jarek May 08 '15 at 20:39
-
thanx jarek.i fixed the problem. it was scalafx version. now i need the same example but with checkBoxTableCell. that's mean i want to add a checkbox to a column in a table. – Achref May 11 '15 at 08:27
-
That is a different question :) – Jarek May 12 '15 at 13:21