This is the code I have. It basically sorts the table based on what the user entered. The problem I have is i cannot retrieve the number of rows after the search. I have tried (rowSorter.getModel().getRowCount()); but it doesnt seem to work.
这是我的代码。它基本上根据用户输入的内容对表进行排序。我遇到的问题是我无法检索搜索后的行数。我试过(rowSorter.getModel()。getRowCount());但似乎没有用。
TableRowSorter<TableModel> rowSorter = new TableRowSorter(jTable.getModel());
jTable.setRowSorter(rowSorter);
String text = SearchTF.getText();
if (text.trim().length() == 0) {
rowSorter.setRowFilter(null);
} else {
rowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
}
1 个解决方案
#1
1
The TableRowSorter
will not affect the model, it generates a "proxy" of the model which the table can use to display the results.
TableRowSorter不会影响模型,它会生成模型的“代理”,表格可以用来显示结果。
Instead, ask the JTable
for the row count - See JTable#getRowCount
相反,请询问JTable的行数 - 请参阅JTable#getRowCount
#1
1
The TableRowSorter
will not affect the model, it generates a "proxy" of the model which the table can use to display the results.
TableRowSorter不会影响模型,它会生成模型的“代理”,表格可以用来显示结果。
Instead, ask the JTable
for the row count - See JTable#getRowCount
相反,请询问JTable的行数 - 请参阅JTable#getRowCount