且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在两列中过滤JTable

更新时间:2023-12-04 19:26:28

在下面的代码中,我注释掉了部分数据,并放入了示例数据,因此无需其他文件即可工作.

In the following code I have commented out a few parts of data and put in sample data so it works without other files.

不仅要注释掉代码,还要从发布中删除代码,这对我们来说不重要.

Don't just comment out the code, remove it from the posting it is of no interest to us.

此外,为什么还要包含按钮的所有代码?这些按钮与问题无关,因此我们不想通读所有代码.读取的代码越少,我们发现问题的可能性就越大.

Also, why did you include all the code for the buttons? The buttons are not related to the problem so we don't want to read through all the code. The less code to read the more likely we can find the problem.

但是我的第二个似乎不起作用.

however my second one does not appear to work.

在我看来就像您有错字:

Looks to me like you have a typo:

//rf = RowFilter.regexFilter(filterAthID.getText(), 1);

您应该使用过滤器的名称(而不是ID):

You should be using the name for the filter (not the ID):

rf = RowFilter.regexFilter(filterForeName.getText(), 1);

同时在两列上进行过滤的示例:

Example of filter on two columns at the same time:

List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2);
filters.add(RowFilter.regexFilter(textField1.getText(), 0));
filters.add(RowFilter.regexFilter(textField2.getText(), 1));
rf = RowFilter.andFilter(filters);