我有一个显示SQL结果的动态JTable。我正在实现一个搜索功能,并选择包含所搜索值的所有单元格。我正在使用JTable.changeSelection(row,col,true,false)。在JTable中,我实现了一个函数,该函数返回一个包含找到元素的行和列的对象的ArrayList。只要有最大值,这个工作正常。 5搜索结果,在此之后它选择某种方式随机。这是我的代码:
private void searchTable() {
String pattern = JOptionPane.showInputDialog(scrollpane, "Pattern", "Find Text in Table", JOptionPane.QUESTION_MESSAGE);
if (pattern != null) {
Thread t = new Thread(new Runnable() {
public void run() {
busyCursor();
ArrayList<TableFindResult> tfr = dt.search(pattern);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
tableView.setColumnSelectionAllowed(true);
tableView.setRowSelectionAllowed(true);
tableView.clearSelection();
int a = 1;
Iterator iter = tfr.iterator();
while (iter.hasNext()) {
TableFindResult t = (TableFindResult) iter.next();
tableView.changeSelection(t.getRow(), t.getCol(), true, false);
}
defaultCursor();
}
});
}
});
t.start();
} else {
tableView.clearSelection();
}
}
当结果少于5时,它就是这样的:
现在我的模式是'8',即使没有8个qazxsw poi也有很多外观
我已经调试验证,搜索功能,准备阵列正常工作。我的印象是JTable.changeSelection函数,它变得一团糟。但到目前为止我还没有找到解决方案。我认为选择heses cell是个好主意,因为我的JdbcTable能够转换选定的行,所以这两个函数会协调一致。有什么好主意吗?非常感谢