将TableRowSorter与scala.swing.Table一起使用 [英] Using TableRowSorter with scala.swing.Table

查看:55
本文介绍了将TableRowSorter与scala.swing.Table一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用具有scala.swing.Table组件的简单UI.我想使用java.swing.table.TableRowSorter对表行进行排序. Table类不提供用于使用行排序器的任何API,因此我尝试直接在对等体上设置它

I'm working on simple UI that has a scala.swing.Table component. I'd like to sort the table rows using java.swing.table.TableRowSorter. The Table class doesn't provide any API for using a row sorter so I tried setting 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 headings I get the little up/down arrows but the table contents don't update with the new sort order. If there's a row selected when I click on the column heading the selection moves to the row where the selected should be in based on the sort order. I've added custom comparators that they get called as expected so the sorting is really happening but the table isn't being updated.

我是否缺少某些东西来更新表?访问基础JTable对等对象是否合法?

Am I missing something to get the table to update? Is it legitimate to access the underlying JTable peer object?

推荐答案

回答我自己的问题.

scala.swing.Table类不支持Java 6中添加的行排序功能.请参见第277行的Table.scala源文件:

The scala.swing.Table class doesn't support the row sorting features added in Java 6. See the Table.scala source file at 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)

我将scala.swing文件移动到另一个包中,并将其构建到我的项目中,然后取消注释Java 6的内容,并注释掉了旧的apply()方法,现在进行了表排序.

I moved the scala.swing files into a different package and built it into my project, then uncommented out the Java 6 stuff and commented out the old apply() method and now table sorting works.

在此的错误报告的链接. Java 6代码是在8月添加的,然后删除,直到Scala库构建切换到Java6.

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

这篇关于将TableRowSorter与scala.swing.Table一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆