我从一个简单的ScalaFx示例中获取了一个TableView代码(从ScalaFx Custom cells简化):
导入scalafx.application.JFXApp import scalafx.beans.property.StringProperty import scalafx.collections.ObservableBuffer 导入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
}
)
}
}
}
}
编译时,我收到一个令人困惑的错误:
Error:(24, 11) type mismatch;
found : scalafx.scene.control.TableColumn[MyTableApp.Person,String]
required: javafx.scene.control.TableColumn[MyTableApp.Person, ?]
new TableColumn[Person, String] {
我做错了什么?
我的build.sbt包含:
scalaVersion := "2.11.8"
libraryDependencies += "org.scalafx" %% "scalafx" % "8.0.60-R9"
答案 0 :(得分:1)
我没有仔细复制示例源,我错过了一个导入:
import scalafx.scene.control.TableColumn._