我从一个简单的TableView示例中获取了一个ScalaFx代码(从ScalaFx自定义单元中简化):
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
}
)
}
}
}
}在编译它时,我会得到一个令人困惑的错误:
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"发布于 2016-03-29 09:33:26
我没有仔细地复制示例源代码,并且丢失了一个导入:
import scalafx.scene.control.TableColumn._https://stackoverflow.com/questions/36269421
复制相似问题