本文介绍了在JTable行中突出显示找到的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从找到数据的JTable
中搜索数据,然后我要突出显示表行.这段代码可以正常搜索记录,但是我不知道该如何突出显示该行.
I want to search data from JTable
when data found then I want to highlight table row. This code is work properly search record but I don't know what I do for highlight the row.
String target = jTextField1.getText();
for(int row = 0; row < jTable1.getRowCount(); row++)
for(int col = 0; col < jTable1.getColumnCount(); col++)
{
String next = (String)jTable1.getValueAt(row, col);
if(next.equals(target))
{
System.out.println("found");// here what change for highlight row.
}
}
推荐答案
我们可以使用自定义JLabel和TableCellRenderer来实现.下面的示例突出显示JTable中找到(过滤)的行.行通过RowFilter进行过滤: http://www.logicbig.com /tutorials/core-java-tutorial/swing/jtable-row-filter-highlighting/
We can achieve that with a custom JLabel and TableCellRenderer.Following example does the highlighting on the found (filtered) rows in JTable. The rows are filtered via RowFilter:http://www.logicbig.com/tutorials/core-java-tutorial/swing/jtable-row-filter-highlighting/
这篇关于在JTable行中突出显示找到的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!