Sortable columns In scala.swing.Table

Consider this example code:

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)
    }
  }

}

      

Why are columns in scalaTable

not sorted when clicking the column name, and columns in myTable

-? And how can I use it scala.swing.Table

with sortable columns instead of overriding it to myTable

?

+2


source to share


1 answer


See my answer to my own question at Using a TableRowSorter with scala.swing.Table . Java 6 table sort functionality is not implemented in scala.swing.Table. The code is commented out.



0


source







All Articles