scalatableviewscalafx

Simple ScalaFx TableView example not compiling


I took a TableView code from a simple ScalaFx example (simplified from ScalaFx Custom cells):

import scalafx.application.JFXApp
import scalafx.beans.property.StringProperty
import scalafx.collections.ObservableBuffer
import scalafx.scene.Scene
import scalafx.scene.control.{TableColumn, TableView}

object MyTableApp extends JFXApp {

  class Person(nameStr : String) {
    val name = new StringProperty(this, "firstName", nameStr)
  }

  val characters = ObservableBuffer[Person](
    new Person("Peggy Sue"),
    new Person("Rocky Raccoon"),
    new Person("Bungalow Bill")
  )

  stage = new JFXApp.PrimaryStage {
    title = "Simple TableView"
    scene = new Scene {
      content = new TableView[Person](characters) {
        columns ++= List(
          new TableColumn[Person, String] {
            text = "First Name"
            cellValueFactory = { _.value.name }
            prefWidth = 100
          }
        )
      }
    }
  }
}

When compiling it, I get a confusing error:

Error:(24, 11) type mismatch;
 found   : scalafx.scene.control.TableColumn[MyTableApp.Person,String]
 required: javafx.scene.control.TableColumn[MyTableApp.Person, ?]
          new TableColumn[Person, String] {

What am I doing wrong?

My build.sbt contains:

scalaVersion := "2.11.8"

libraryDependencies += "org.scalafx" %% "scalafx" % "8.0.60-R9"

Solution

  • I did not copy the example source carefully, and I was missing an import:

    import scalafx.scene.control.TableColumn._