value starts with "a", include it return true; } } // None of the columns start with "a"; return false so that this // entry is not shown return false; } };
RowFilter
has two formal type parameters that allow you to create a
RowFilter
for a specific model. For example, the following assumes a specific model that is wrapping objects of type
Person
. Only
Person
s with an age over 20 will be shown:
RowFilter<PersonModel,Integer> ageFilter = new RowFilter<PersonModel,Integer>() { public boolean include(Entry<? extends PersonModel, ? extends Integer> entry) { PersonModel personModel = entry.getModel(); Person person = personModel.getPerson(entry.getIdentifier()); if (person.getAge() > 20) { // Returning true indicates this row should be shown. return true; } // Age is <= 20, don't show it. return false; } }; PersonModel model = createPersonModel(); TableRowSorter<PersonModel> sorter = new TableRowSorter<PersonModel>(model); sorter.setRowFilter(ageFilter);
@param < M> the type of the model; for example
PersonModel
@param < I> the type of the identifier; when using
TableRowSorter
this will be
Integer
@see javax.swing.table.TableRowSorter
@since 1.6