Here is an example of an editable check box used together with BooleanProperty:
import scalafx.Includes._
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.beans.property.{BooleanProperty, StringProperty}
import scalafx.collections.ObservableBuffer
import scalafx.scene.Scene
import scalafx.scene.control.TableColumn._
import scalafx.scene.control.cell.{CheckBoxTableCell, TextFieldTableCell}
import scalafx.scene.control.{TableColumn, TableView}
object SimpleEditableTableView extends JFXApp {
class Person(firstName_ : String, age_ : Int, cool_ : java.lang.Boolean) {
val name = new StringProperty(this, "Name", firstName_)
val cool = new BooleanProperty(this, "Cool", cool_)
}
val characters = ObservableBuffer[Person](
new Person("Peggy", 45, false),
new Person("Rocky", 43, true)
)
// Print changes
characters.zipWithIndex.foreach {
case (c, i) => c.cool.onChange((_, oldValue, newValue) => println(i + " changed from " + oldValue + " to " + newValue))
}
val coolColumn = new TableColumn[Person, java.lang.Boolean] {
text = "Cool"
cellValueFactory = _.value.cool.delegate
prefWidth = 180
}
coolColumn.setCellFactory(CheckBoxTableCell.forTableColumn(coolColumn))
stage = new PrimaryStage {
title = "Simple Table View"
scene = new Scene {
content = new TableView[Person](characters) {
editable = true
columns ++= List(
new TableColumn[Person, String] {
text = "First Name"
prefWidth = 180
},
coolColumn
)
}
}
}
}