Java:排序时行索引不会更改

发布于 2025-01-23 10:32:53 字数 394 浏览 1 评论 0原文

当我对行进行排序时,行的索引似乎根本没有变化 - 因此导致旧行最初在制作任何形式之前处于该位置。 在这里我的代码是

DefaultTableModel  modelmachine = (DefaultTableModel) jTableMachine2.getModel();
        TableRowSorter<DefaultTableModel> tr = new TableRowSorter<>(modelmachine);
        jTableMachine2.setRowSorter(tr);
        tr.setRowFilter(RowFilter.regexFilter(jTextField8.getText()));

when I sort the row, the indexes of the rows doesn't seems to change at all - thus resulting the old row which was initially in that position before making any sort.
here my code is

DefaultTableModel  modelmachine = (DefaultTableModel) jTableMachine2.getModel();
        TableRowSorter<DefaultTableModel> tr = new TableRowSorter<>(modelmachine);
        jTableMachine2.setRowSorter(tr);
        tr.setRowFilter(RowFilter.regexFilter(jTextField8.getText()));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把昨日还给我 2025-01-30 10:32:53

查看Rowsorter的ConverTrowIndextomodelconvertrowIndextoview方法。您可能会获取模型索引(模型中的索引,没有应用分类),但是您需要视图索引(您实际看到的索引)。

Check out RowSorter's convertRowIndexToModel and convertRowIndexToView methods. You're probably getting the model index (the index in the model, which does not have the sorting applied), but you need the view index (the index of what you actually see).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文