java.lang.Objectjavax.swing.RowFilter<M,I>
public abstract class RowFilter<M,I>
RowFilter is used to filter out entries from the model so that they are not shown in the view. For example, a RowFilter associated with a JTable might only allow rows that contain a column with a specific string. The meaning of entry depends on the component type. For example, when a filter is associated with a JTable, an entry corresponds to a row; when associated with a JTree, an entry corresponds to a node.
Subclasses must override the include method to indicate whether the entry should be shown in the view. The Entry argument can be used to obtain the values in each of the columns in that entry. The following example shows an include method that allows only entries containing one or more values starting with the string "a":
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 Persons with an age over 20 will be shown:RowFilter<Object,Object>
RowFilterstartsWithAFilter = new RowFilter<Object,Object>() { public boolean include(Entry<? extends Object, ? extends Object> entry) { for (int i = entry.getValueCount() - 1; i >= 0; i--) { if (entry.getStringValue(i).startsWith("a")) { // The 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<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);
Nested Class Summary | |
---|---|
static class |
RowFilter.ComparisonType
Enumeration of the possible comparison values supported by some of the default RowFilters. |
static class |
RowFilter.Entry
<
M
,
I
>
An Entry object is passed to instances of RowFilter, allowing the filter to get the value of the entry's data, and thus to determine whether the entry should be shown. |
Constructor Summary | |
---|---|
RowFilter
() |
Method Summary | ||||
---|---|---|---|---|
static
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Returns a RowFilter that includes entries if all of the supplied filters include the entry. |
|||
![]()
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|||
abstract boolean |
include
(
RowFilter.Entry
<? extends
M
,? extends
I
> entry) Returns true if the specified entry should be shown; returns false if the entry should be hidden. |
|||
static
|
notFilter
(
RowFilter
<M,I> filter) Returns a RowFilter that includes entries if the supplied filter does not include the entry. |
|||
![]()
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|||
static
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Returns a RowFilter that includes entries if any of the supplied filters includes the entry. |
|||
![]()
|
![]() ![]() ![]() ![]() ![]() |
Methods inherited from class java.lang. Object |
---|
clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
Constructor Detail |
---|
public RowFilter()
Method Detail |
---|
public static<M,I> RowFilter
<M,I>
<Object,Object>regexFilter(String regex, int... indices)
RowFilter.regexFilter("^a");
The returned filter uses Matcher.find() to test for inclusion. To test for exact matches use the characters '^' and '$' to match the beginning and end of the string respectively. For example, "^foo$" includes only rows whose string is exactly "foo" and not, for example, "food". See Pattern for a complete description of the supported regular-expression constructs.
public static<M,I> RowFilter
<M,I>
<Object,Object>dateFilter(RowFilter.ComparisonType type, Date date, int... indices)
RowFilter.dateFilter(ComparisonType.AFTER, new Date());
public static<M,I> RowFilter
<M,I>
<Object,Object>numberFilter(RowFilter.ComparisonType type, Number number, int... indices)
RowFilter.numberFilter(ComparisonType.EQUAL, 10);
public static <M,I> RowFilter<M,I> orFilter(Iterable
List<? extends
RowFilter
<RowFilter<? super M,? super I>> filters)
<M,I>> filters)
The following example creates a RowFilter that will include any entries containing the string "foo" or the string "bar":
List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2); filters.add(RowFilter.regexFilter("foo")); filters.add(RowFilter.regexFilter("bar")); RowFilter<Object,Object> fooBarFilter = RowFilter.orFilter(filters);
public static <M,I> RowFilter<M,I> andFilter(Iterable
List<? extends
RowFilter
<RowFilter<? super M,? super I>> filters)
<M,I>> filters)
The following example creates a RowFilter that will include any entries containing the string "foo" and the string "bar":
List<RowFilter<Object,Object>> filters = new ArrayList<RowFilter<Object,Object>>(2); filters.add(RowFilter.regexFilter("foo")); filters.add(RowFilter.regexFilter("bar")); RowFilter<Object,Object> fooBarFilter = RowFilter.andFilter(filters);
public static <M,I> RowFilter<M,I> notFilter(RowFilter<M,I> filter)
public abstract boolean include(RowFilter.Entry<? extends M,? extends I> entry)
The entry argument is valid only for the duration of the invocation. Using entry after the call returns results in undefined behavior.