Java:选定行的索引在排序时不会更改 [英] Java: Selected rows's index does not changes when sorted

查看:152
本文介绍了Java:选定行的索引在排序时不会更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Jtable,我在其上调用了方法
table1.setAutoCreateRowSorter(true);
所以这很好用。
但我在JFrame类中也有一个方法,当我按下按钮时会触发它。它使用以下代码获取选定的行索引
int selectedRows [] = this.table1.getSelectedRows();
并显示所选时间间隔内对应的第一行的编辑窗口。

I have a Jtable on which I called the method table1.setAutoCreateRowSorter(true);. So this works on well. But I also have a methos in my JFrame class which is fired when i push a button. It gets the selected rows indexes using this code int selectedRows[] = this.table1.getSelectedRows();. And displays an edit window for the first row corresponding in the selected interval.

问题是,如果我没有点击列的标题(我的意思是我根本不打趣他们的方法我的方法很完美。但是当我对行进行排序时,行的索引似乎根本没有变化 - 从而导致旧行的编辑窗口最初在进行任何排序之前处于该位置。

The problem is that if I don't click on column's headers (I mean i don't sorte them at all) my method works perfect. But when I sort the row, the indexes of the rows doesn't seems to change at all - thus resulting an edit window for the old row whicn was initially in that position before making any sort.

我使用的是JDK 6可以给你一个提示吗?

I am using JDK 6 could anyonw give ma a tip?

推荐答案

底层模型不会改变顺序。只有视图更改。您可以在 Sun的教程中阅读更多相关信息。 。您将需要使用JTable.convertRowIndexToView()和JTable.convertRowIndexToModel()。

The underlying model does not change order. Only the view changes. You can read more about this in Sun's tutorial. You will need to use JTable.convertRowIndexToView() and JTable.convertRowIndexToModel().

这篇关于Java:选定行的索引在排序时不会更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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