JXTable ConvertRowIndexToModel 排序后结果错误?
我有一个 JXTable,其中模型是不同对象的列表。当我在按所选列标题对视图进行排序后尝试将视图索引映射到模型索引时出现问题。使用此代码,
int[] selecteds = getTableMember().getSelectedRows();
if (selecteds != null && selecteds.length > 0) {
for (int row : selecteds) {
int rr = getTableMember().convertRowIndexToModel(row);
System.out.println(row+":"+rr);
}
}
我得到以下结果:
11:240 12:328 13:1174 14:328 15:1174
我无法理解为什么不同的视图索引映射到相同的模型索引?
已解决的问题: 我在修改每行后立即调用了 fireTableRowsUpdated,因此所选索引不再正确。
I have a JXTable
in which a model is a List
of distinct objects. There is a problem when I try to map the view index to model index after sorting the view by the selected column header. Using this code,
int[] selecteds = getTableMember().getSelectedRows();
if (selecteds != null && selecteds.length > 0) {
for (int row : selecteds) {
int rr = getTableMember().convertRowIndexToModel(row);
System.out.println(row+":"+rr);
}
}
I get this result:
11:240 12:328 13:1174 14:328 15:1174
I cannot understand why different view indexes map to the same model index?
Solved problem:
I called fireTableRowsUpdated right after modify per row so the selected index is not correct anymore.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
验证
List
中的对象实际上是不同的。特别是Comparator
< /a> 由DefaultRowSorter
必须正确实现。请注意,默认值依赖于底层对象的toString()
方法,但您可以指定自己的实现。Verify that the objects in the
List
are in fact distinct. In particular, theComparator
used byDefaultRowSorter
must be implemented correctly. Note that the default relies on thetoString()
method of the underlying objects, but you can specify your own implementation.