swingscalajtabletablerowsorter

Swing Table - sorting numbers is wrong (uses toString representation)


I'm baffled by a Scala-Swing Table not correctly sorting numbers when setting t.peer.setAutoCreateRowSorter(true).

This is from my table model:

  override def getColumnClass(colIdx: Int): Class[_] =
    (colIdx: @switch) match {
      case 0 => classOf[Int]
      case 1 => classOf[String]
      case 2 => classOf[Double]
    }

But it appears the first and third column are sorted by string representation instead.


Solution

  • There seems to be a mismatch with primitive types and Java expecting AnyRef instances. The following works:

      override def getColumnClass(colIdx: Int): Class[_] =
        (colIdx: @switch) match {
          case 0 => classOf[java.lang.Integer]
          case 1 => classOf[String]
          case 2 => classOf[java.lang.Double]
        }