Java:排序时行索引不会更改
当我对行进行排序时,行的索引似乎根本没有变化 - 因此导致旧行最初在制作任何形式之前处于该位置。 在这里我的代码是
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看Rowsorter的
ConverTrowIndextomodel
和convertrowIndextoview
方法。您可能会获取模型索引(模型中的索引,没有应用分类),但是您需要视图索引(您实际看到的索引)。Check out RowSorter's
convertRowIndexToModel
andconvertRowIndexToView
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).