Using TableRowSorter with scala.swing.Table

I am working on a simple UI that has a scala.swing.Table component. I would like to sort the rows of a table using java.swing.table.TableRowSorter. The Table class does not provide an API for using the row sorter, so I tried to install it directly on the peer

val table = new Table(height, width) {
  import javax.swing.table._
  rowHeight = 25
  autoResizeMode = Table.AutoResizeMode.NextColumn
  showGrid = true
  gridColor = new java.awt.Color(150, 150, 150)
  model = myModel

  peer.setRowSorter(new TableRowSorter(model))
}

      

Now, when I click on the column headers, I get small up / down arrows, but the table contents are not updated with the new sort order. If the row selected, when I click on the column header, the selection moves to the row where the selected should be selected, according to the sort order. I added custom comparators that are called as expected, so the sort actually happens, but the table is not updated.

Am I missing something to update the table? Is the underlying JTable peer object legal to access?

+3


source to share


1 answer


Answering my own question.

The scala.swing.Table class does not support the string sorting features added in Java 6. See the original Table.scala file on line 277:

def apply(row: Int, column: Int): Any = model.getValueAt(row, viewToModelColumn(column))

// TODO: this is Java 6 stuff
// def apply(row: Int, column: Int): Any = model.getValueAt(viewToModelRow(row), viewToModelColumn(column))
//def viewToModelRow(idx: Int) = peer.convertRowIndexToModel(idx)
//def modelToViewRow(idx: Int) = peer.convertRowIndexToView(idx)

      



I moved the scala.swing files to another package and put it in my project, then uncommented the Java 6 stuff and commented out the old apply () method and the table sorting now works.

Here's a link to the bug report. Java 6 code was added back in August and then removed until the Scala library build switches to Java 6.

+1


source







All Articles