I am new to ScalaFX. I am trying to adapt a basic TableView example, to include Integer columns.
So far, I have come up with the following code:
class Person(firstName_ : String, age_ : Int) {
val name = new StringProperty(this, "Name", firstName_)
val age = new IntegerProperty(this, "Age", age_)
}
object model{
val dataSource = new ObservableBuffer[Person]()
dataSource += new Person("Moe", 45)
dataSource += new Person("Larry", 43)
dataSource += new Person("Curly", 41)
dataSource += new Person("Shemp", 39)
dataSource += new Person("Joe", 37)
}
object view{
val nameCol = new TableColumn[Person, String]{
text = "Name"
cellValueFactory = {_.value.name}
}
val ageCol = new TableColumn[Person, Int]{
text = "Age"
cellValueFactory = {_.value.age}
}
}
object TestTableView extends JFXApp {
stage = new PrimaryStage {
title = "ScalaFx Test"
width = 800; height = 500
scene = new Scene {
content = new TableView[Person](model.dataSource){
columns += view.nameCol
columns += view.ageCol
}
}
}
}
The problem is that, while the nameCol
works well, the ageCol
doesn't even compile.
In the line cellValueFactory = {_.value.age}
, I get a type mismatch error. It is expecting a ObservableValue[Int,Int]
but getting an IntegerProperty
.
I am using ScalaFX 1.0 M2, compiled for Scala 2.10.