0

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...

mdewitt
  • 2,526
  • 19
  • 23
user2582318
  • 1,607
  • 5
  • 29
  • 47

1 Answers1

4

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 ANDs or ORs 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);
mdewitt
  • 2,526
  • 19
  • 23