简体   繁体   中英

Set Multiple RowFilters On JXTable

How can i add more than one filter for 1 Row in JXTable?

I tried using:

int col = jxTable.getColumn("Tipo").getModelIndex();
RowFilter filter1 = RowFilters.regexFilter(0, "^N", col)
RowFilter filter2 = RowFilters.regexFilter(0, "^N", col)

jxTable.setRowFilter(filter1);
jxTable.setRowFilter(filter2);

but filter2 overwrites the filter1

the usage:

I will do 3 checks box with different letters to filter,

[ ]A  [ ]B  [ ]C

if you check A, just show what start with A, if you check B and A, display both...

Use the RowFilter.andFilter() or RowFilter.orFilter() methods when you want to combine more than one filter. For your situation, it sounds like you want to use the orFilter method

Steps:

  • Take all the filters you want to add to the table and put them in a list
  • call RowFilter.andFilter() or RowFilter.orFilter() to create a single filter that AND s or OR s the filters from the list.
  • Apply the newly created AND or OR filter created to the JXTable.

Example:

//Code not tested
int col = jxTable.getColumn("Tipo").getModelIndex();
RowFilter filter1 = RowFilters.regexFilter(0, "^N", col)
RowFilter filter2 = RowFilters.regexFilter(0, "^N", col)

List<RowFilter> filters = new ArrayList<RowFilter>();
filters.add(filter1);
filters.add(filter2)
RowFilter orFilter = RowFilter.orFilter(filters);
jxTable.setRowFilter(orFilter);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM