[英]Simple ScalaFx TableView example not compiling
I took a TableView code from a simple ScalaFx example (simplified from ScalaFx Custom cells ):我从一个简单的 ScalaFx 示例(从ScalaFx 自定义单元格简化)中获取了一个 TableView 代码:
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:我的 build.sbt 包含:
scalaVersion := "2.11.8"
libraryDependencies += "org.scalafx" %% "scalafx" % "8.0.60-R9"
我没有仔细复制示例源代码,并且丢失了一个导入:
import scalafx.scene.control.TableColumn._
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.