[英]ScalaFX TableView - simple example compiler error
I am just trying to get familiar with ScalaFX, and my Scala knowledge is also still in embryo phase. 我只是想熟悉ScalaFX,而我的Scala知识也仍处于萌芽阶段。 Can you please help me out, in the following simple problem? 在以下简单问题中,您能帮我什么忙吗?
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.collections.ObservableBuffer
import scalafx.scene.Scene
import scalafx.scene.control.TableColumn._
import scalafx.scene.control.{TableCell, TableColumn, TableView}
object Gui extends JFXApp {
case class listInfo(text: String, subtexts: List[String], thumbnail: String, attributeField: Int)
val demo = ObservableBuffer[listInfo](
new listInfo("dewdfasc", subtexts = List("first", "second"), "tdsam", 1),
new listInfo("hgfhfghn", subtexts = List("first", "second"), "tdsacdsm", 2)
)
stage = new PrimaryStage {
title = "ScalaFX Hello World"
scene = new Scene {
root = TableView[listInfo](demo) {
columns ++= List(
new TableColumn[listInfo, String] {
text = "band"
cellValueFactory = {_.value.text}
prefWidth = 100
},
new TableColumn[listInfo, String] {
text = "thumbnail"
cellValueFactory = {_.value.thumbnail}
prefWidth = 100
}
)
}
}
}
}
has the following compiler error: 具有以下编译器错误:
Error:(20, 23) object TableView does not take type parameters.
root = TableView[listInfo](demo) {
Error:(21, 9) not found: value columns
columns ++= List(
Error:(24, 41) type mismatch;
found : String
required: scalafx.beans.value.ObservableValue[String,String]
cellValueFactory = {_.value.text}
Error:(29, 41) type mismatch;
found : String
required: scalafx.beans.value.ObservableValue[String,String]
cellValueFactory = {_.value.thumbnail}
my environment: 我的环境:
java 1.8 Java 1.8
scala 2.12 斯卡拉2.12
scalafx 2.11-8.0.144-R12 scalafx 2.11-8.0.144-R12
What should I correct, so that it compiles? 我应该纠正什么以便编译?
Thanks in advance! 提前致谢!
import scalafx.application.JFXApp
import scalafx.beans.property.StringProperty
import scalafx.collections.ObservableBuffer
import scalafx.scene.Scene
import scalafx.scene.control.TableColumn._
import scalafx.scene.control.{ TableColumn, TableView }
object Gui extends JFXApp {
case class ListInfo(_text: String, _subtexts: List[String], _thumbnail: String, _attributeField: Int) {
val text = new StringProperty(this, "text", _text)
val thumbnail = new StringProperty(this, "thumbnail", _thumbnail)
}
val demo = ObservableBuffer[ListInfo](
ListInfo("dewdfasc", List("first", "second"), "tdsam", 1),
ListInfo("hgfhfghn", List("first", "second"), "tdsacdsm", 2)
)
stage = new JFXApp.PrimaryStage {
title.value = "ScalaFX Hello World"
scene = new Scene {
root = new TableView[ListInfo](demo) {
columns ++= List(
new TableColumn[ListInfo, String] {
text = "band"
cellValueFactory = _.value.text
prefWidth = 100
},
new TableColumn[ListInfo, String] {
text = "thumbnail"
cellValueFactory = _.value.thumbnail
prefWidth = 100
}
)
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.