簡體   English   中英

簡單的 ScalaFx TableView 示例未編譯

[英]Simple ScalaFx TableView example not compiling

我從一個簡單的 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
          }
        )
      }
    }
  }
}

編譯時,我收到一個令人困惑的錯誤:

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"

我沒有仔細復制示例源代碼,並且丟失了一個導入:

import scalafx.scene.control.TableColumn._

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM