可排序列在scala.swing.Table中

时间:2012-01-18 14:26:52

标签: scala swing

考虑这个示例代码:

import swing._
import Swing._
import javax.swing.JTable
import javax.swing.table.AbstractTableModel


class MyTable(columnNames: Seq[String], model: Seq[Seq[Any]]) extends Component {
  override lazy val peer = new JTable(new AbstractTableModel {
    def getValueAt(row: Int, col: Int): AnyRef = model(row)(col).asInstanceOf[AnyRef]
    def getColumnCount() = columnNames.length
    def getRowCount() = model.length
    override def isCellEditable(row: Int, column: Int) = false
  })
  peer setAutoCreateRowSorter true
}


object SO extends SimpleSwingApplication {

  implicit def tabelRowData2Array[T](rowData: Seq[Seq[T]]) = rowData.map(_.toArray[Any]).toArray

  val rowData     = Seq(Seq("1"), Seq("2"), Seq("3"))
  val columnNames = Seq("Nr")

  def top = new MainFrame {
    title = "TableTest"
    val scalaTable = new Table(rowData,columnNames) {
      peer setAutoCreateRowSorter true
    }
    val myTable = new MyTable(columnNames,rowData)
    contents = new BoxPanel(Orientation.Horizontal) {
      contents += new ScrollPane(scalaTable)
      contents += new ScrollPane(myTable)
    }
  }

}

scalaTable中的列为myTable时,为什么scala.swing.Table中的列无法排序? 如何将MyTable与可排序列一起使用,而不是{{1}}重新实现?

1 个答案:

答案 0 :(得分:0)

Using TableRowSorter with scala.swing.Table查看我对自己问题的回答。 scala.swing.Table中未实现Java 6表排序功能。代码已注释掉。