Scala:JavaFx Tableview不显示数据

时间:2015-12-03 10:38:27

标签: scala javafx tableview

所以我试图将一些数据加载到我的Tableview中,但它不起作用,因为每次启动我的应用程序时,tableview都是空的,但它没有显示实际为空的提示消息。

我的代码:

     @FXML var anchorpane: AnchorPane = _

  // Example for the Product Entity
  @FXML var tableview: TableView[Product] = _
  @FXML var c1: TableColumn[Product,Integer] = _
  @FXML var c2: TableColumn[Product,String] = _
  @FXML var c3: TableColumn[Product,Double] = _



  //create data for inserting in an observerList
  val data: ObservableList[Product] = FXCollections.observableArrayList(
    new Product(55,"hallo",33.0)
    new Product(10,"hello",20.3)
  )



  override def initialize(location: URL, resources: ResourceBundle): Unit = {
    //Für die columns namen setzen
    c1.setCellValueFactory(new PropertyValueFactory[Product,Integer]("id"))
    c2.setCellValueFactory(new PropertyValueFactory[Product,String]("name"))
    c3.setCellValueFactory(new PropertyValueFactory[Product,Double]("price"))

    //inserting data from the observableArrayList
    tableview.setItems(data)
  }

但我的桌面视图仍然是空的...... 这是它的样子: My App with the tableview

我的产品类:

    package fhj.swengb.homework.dbtool

import java.sql.{ResultSet, Connection, Statement}

import scala.collection.mutable.ListBuffer

/**
  * Created by loete on 27.11.2015.
  */

object Product extends Db.DbEntity[Product] {

  val dropTableSql = "drop table if exists product"
  val createTableSql = "create table product (id integer, name string, price double)"
  val insertSql = "insert into product (id, name, price) VALUES (?, ?, ?)"


  def reTable(stmt: Statement): Int = {
    stmt.executeUpdate(Product.dropTableSql)
    stmt.executeUpdate(Product.createTableSql)
  }

  def toDb(c: Connection)(p: Product): Int = {
    val pstmt = c.prepareStatement(insertSql)
    pstmt.setInt(1, p.id)
    pstmt.setString(2, p.name)
    pstmt.setDouble(3, p.price)
    pstmt.executeUpdate()
  }

  def fromDb(rs: ResultSet): List[Product] = {
    val lb: ListBuffer[Product] = new ListBuffer[Product]()
    while (rs.next()) lb.append(Product(rs.getInt("id"), rs.getString("name"), rs.getDouble("price")))
    lb.toList
  }

  def queryAll(con: Connection): ResultSet = query(con)("select * from product")

}

case class Product(id:Int, name: String, price:Double) extends Db.DbEntity[Product] {

  def reTable(stmt: Statement): Int = 0

  def toDb(c: Connection)(t: Product): Int = 0

  def fromDb(rs: ResultSet): List[Product] = List()

  def dropTableSql: String = "drop table if exists product"

  def createTableSql: String = "create table product (id integer, name String, price Double"

  def insertSql: String = "insert into person (id, name, price) VALUES (?, ?, ?)"

}

0 个答案:

没有答案