PersonModel
TableRowSorter this will be Integer
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<Object,Object> startsWithAFilter = 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 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<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);
javax.swing.table.TableRowSorter
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| public static enum | RowFilter.
Enumeration of the possible comparison values supported by
some of the default |
| private static class | |
| public abstract static class | RowFilter.
the type of the model; for example M, PersonModelthe type of the identifier; when using
I>TableRowSorter this will be IntegerAn |
| private abstract static class | |
| private static class | |
| private static class | |
| private static class | |
| private static class |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public static < the type of the model the M, RowFilter applies tothe type of the identifier passed to the I> RowFilterRowFilter | |
| private static void | checkIndices(int[] columns)
Throws an IllegalArgumentException if any of the values in columns are < 0. |
| public static < the type of the model to which the M, RowFilter appliesthe type of the identifier passed to the I> RowFilterRowFilter | Returns: aRowFilter implementing the specified criteriathe type of comparison to perform type,the date to compare against date, int... the indices of the values to check. If not supplied all
values are evaluated indices)Returns a |
| public abstract boolean | |
| public static < the type of the model to which the M, RowFilter appliesthe type of the identifier passed to the I> RowFilterRowFilter | |
| public static < the type of the model to which the M, RowFilter appliesthe type of the identifier passed to the I> RowFilterRowFilter | Returns: aRowFilter implementing the specified criteriathe type of comparison to perform type,a number, int... Number value to compare againstthe indices of the values to check. If not supplied all
values are evaluated indices)Returns a |
| public static < the type of the model to which the M, RowFilter appliesthe type of the identifier passed to the I> RowFilterRowFilter | |
| public static < the type of the model to which the M, RowFilter appliesthe type of the identifier passed to the I> RowFilterRowFilter | Returns: aRowFilter implementing the specified criteriathe regular expression to filter on regex, int... the indices of the values to check. If not supplied all
values are evaluated indices)Returns a |
| RowFilter | back to summary |
|---|---|
| protected RowFilter() Constructor for subclasses to call. | |
| andFilter | back to summary |
|---|---|
| public static <M, I> RowFilter Returns a
The following example creates a
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);
| |
| checkIndices | back to summary |
|---|---|
| private static void checkIndices(int[] columns) Throws an IllegalArgumentException if any of the values in columns are < 0. | |
| dateFilter | back to summary |
|---|---|
| public static <M, I> RowFilter Returns a RowFilter.dateFilter(ComparisonType.AFTER, new Date());
| |
| include | back to summary |
|---|---|
| public abstract boolean include(RowFilter. Returns true if the specified entry should be shown; returns false if the entry should be hidden.
The | |
| notFilter | back to summary |
|---|---|
| public static <M, I> RowFilter Returns a
| |
| numberFilter | back to summary |
|---|---|
| public static <M, I> RowFilter Returns a RowFilter.numberFilter(ComparisonType.EQUAL, 10);
| |
| orFilter | back to summary |
|---|---|
| public static <M, I> RowFilter Returns a
The following example creates a
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);
| |
| regexFilter | back to summary |
|---|---|
| public static <M, I> RowFilter Returns a
RowFilter.regexFilter("^a");
The returned filter uses
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | include(RowFilter.
Overrides javax. Returns true if the specified entry should be shown; returns false if the entry should be hidden. |
| AndFilter | back to summary |
|---|---|
| pack-priv AndFilter(Iterable<? extends RowFilter<? super M, ? super I>> filters) | |
| include | back to summary |
|---|---|
| public boolean include(RowFilter. Overrides javax. Doc from javax. Returns true if the specified entry should be shown; returns false if the entry should be hidden.
The | |
RowFilters.
RowFilter
| Modifier and Type | Field and Description |
|---|---|
| public static final RowFilter. | AFTER
Indicates that entries with a value after the supplied value should be included. |
| public static final RowFilter. | BEFORE
Indicates that entries with a value before the supplied value should be included. |
| public static final RowFilter. | EQUAL
Indicates that entries with a value equal to the supplied value should be included. |
| public static final RowFilter. | NOT_EQUAL
Indicates that entries with a value not equal to the supplied value should be included. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static RowFilter. | |
| public static RowFilter. |
| AFTER | back to summary |
|---|---|
| public static final RowFilter. Indicates that entries with a value after the supplied value should be included. | |
| BEFORE | back to summary |
|---|---|
| public static final RowFilter. Indicates that entries with a value before the supplied value should be included. | |
| EQUAL | back to summary |
|---|---|
| public static final RowFilter. Indicates that entries with a value equal to the supplied value should be included. | |
| NOT_EQUAL | back to summary |
|---|---|
| public static final RowFilter. Indicates that entries with a value not equal to the supplied value should be included. | |
| ComparisonType | back to summary |
|---|---|
| private ComparisonType() | |
| valueOf | back to summary |
|---|---|
| public static RowFilter. | |
| values | back to summary |
|---|---|
| public static RowFilter. | |
| Modifier and Type | Field and Description |
|---|---|
| private long | |
| private RowFilter. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | include(RowFilter.
Implements abstract javax.
|
| date | back to summary |
|---|---|
| private long date | |
| type | back to summary |
|---|---|
| private RowFilter. | |
| DateFilter | back to summary |
|---|---|
| pack-priv DateFilter(RowFilter. | |
| include | back to summary |
|---|---|
| protected boolean include(RowFilter. Implements abstract javax.
| |
PersonModel
TableRowSorter this will be Integer
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.
An Entry object contains information about the model
as well as methods for getting the underlying values from the model.
javax.swing.RowFilter , javax.swing.DefaultRowSorter#setRowFilter(javax.swing.RowFilter)
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public abstract I | Returns: a model-based (not view-based) identifier for this entryReturns the identifier (in the model) of the entry. |
| public abstract M | Returns: the model containing the data that this entry representsReturns the underlying model. |
| public String | Returns: non-null string at the specified indexthe index of the value to get index)Returns the string value at the specified index. |
| public abstract Object | Returns: value at the specified indexthe index of the value to get index)Returns the value at the specified index. |
| public abstract int | Returns: number of values in the object being filteredReturns the number of values in the entry. |
| Entry | back to summary |
|---|---|
| public Entry() Creates an | |
| getIdentifier | back to summary |
|---|---|
| public abstract I getIdentifier() Returns the identifier (in the model) of the entry.
For a table this corresponds to the index of the row in the model,
expressed as an
| |
| getModel | back to summary |
|---|---|
| public abstract M getModel() Returns the underlying model.
| |
| getStringValue | back to summary |
|---|---|
| public String getStringValue(int index) Returns the string value at the specified index. If
filtering is being done based on
This implementation calls
| |
| getValue | back to summary |
|---|---|
| public abstract Object getValue(int index) Returns the value at the specified index. This may return
| |
| getValueCount | back to summary |
|---|---|
| public abstract int getValueCount() Returns the number of values in the entry. For example, when used with a table this corresponds to the number of columns.
| |
| Modifier and Type | Field and Description |
|---|---|
| private int[] |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | include(RowFilter.
Implements abstract javax. Returns true if the specified entry should be shown; returns false if the entry should be hidden. |
| protected abstract boolean |
| columns | back to summary |
|---|---|
| private int[] columns | |
| GeneralFilter | back to summary |
|---|---|
| pack-priv GeneralFilter(int[] columns) | |
| include | back to summary |
|---|---|
| public boolean include(RowFilter. Implements abstract javax. Doc from javax. Returns true if the specified entry should be shown; returns false if the entry should be hidden.
The
| |
| include | back to summary |
|---|---|
| protected abstract boolean include(RowFilter. | |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | include(RowFilter.
Implements abstract javax. Returns true if the specified entry should be shown; returns false if the entry should be hidden. |
| filter | back to summary |
|---|---|
| private RowFilter<M, I> filter | |
| NotFilter | back to summary |
|---|---|
| pack-priv NotFilter(RowFilter<M, I> filter) | |
| include | back to summary |
|---|---|
| public boolean include(RowFilter. Implements abstract javax. Doc from javax. Returns true if the specified entry should be shown; returns false if the entry should be hidden.
The | |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private Number | |
| private RowFilter. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | include(RowFilter.
Implements abstract javax.
|
| private int |
| isComparable | back to summary |
|---|---|
| private boolean isComparable | |
| number | back to summary |
|---|---|
| private Number number | |
| type | back to summary |
|---|---|
| private RowFilter. | |
| NumberFilter | back to summary |
|---|---|
| pack-priv NumberFilter(RowFilter. | |
| include | back to summary |
|---|---|
| protected boolean include(RowFilter. Implements abstract javax.
| |
| longCompare | back to summary |
|---|---|
| private int longCompare(Number o) | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv List |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | include(RowFilter.
Implements abstract javax. Returns true if the specified entry should be shown; returns false if the entry should be hidden. |
| filters | back to summary |
|---|---|
| pack-priv List<RowFilter<? super M, ? super I>> filters | |
| OrFilter | back to summary |
|---|---|
| pack-priv OrFilter(Iterable<? extends RowFilter<? super M, ? super I>> filters) | |
| include | back to summary |
|---|---|
| public boolean include(RowFilter. Implements abstract javax. Doc from javax. Returns true if the specified entry should be shown; returns false if the entry should be hidden.
The | |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | include(RowFilter.
Implements abstract javax.
|
| matcher | back to summary |
|---|---|
| private Matcher matcher | |
| RegexFilter | back to summary |
|---|---|
| pack-priv RegexFilter(Pattern regex, int[] columns) | |
| include | back to summary |
|---|---|
| protected boolean include(RowFilter. Implements abstract javax.
| |