- java.lang.Object
-
- javax.swing.RowFilter<M,I>
-
- 参数类型
-
M- 模型的类型; 例如PersonModel -
I- 标识符的类型; 当使用TableRowSorter这将是Integer
public abstract class RowFilter<M,I> extends Object
RowFilter用于过滤模型中的条目,以便它们不会在视图中显示。 例如,与RowFilter相关联的JTable可能只允许包含具有特定字符串的列的行。 条目的含义取决于组件类型。 例如,当过滤器与JTable相关联时,条目对应于一行; 当与JTree相关联时,条目对应于节点。子类必须覆盖
include方法,以指示该条目是否应在视图中显示。Entry参数可用于获取该条目中每个列中的值。 以下示例显示了一个include方法,该方法仅允许包含以字符串“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具有两种正式类型参数,允许您为特定型号创建一个RowFilter。 例如,以下假设是包装类型为Person对象的特定模型。 只有Person年龄在20岁以下才会显示: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);- 从以下版本开始:
- 1.6
- 另请参见:
-
TableRowSorter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 描述 static classRowFilter.ComparisonType枚举一些默认的RowFilters支持的可能比较值。static classRowFilter.Entry<M,I>一个Entry对象传递给RowFilter实例,允许过滤器获取条目数据的值,从而确定该条目是否应该显示。
-
构造方法摘要
构造方法 Constructor 描述 RowFilter()
-
方法摘要
所有方法 静态方法 接口方法 抽象方法 具体的方法 Modifier and Type 方法 描述 static <M,I> RowFilter<M,I>andFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)如果所有提供的过滤器都包含条目,则返回一个包含条目的RowFilter。static <M,I> RowFilter<M,I>dateFilter(RowFilter.ComparisonType type, Date date, int... indices)返回一个RowFilter,其中包含符合指定条件的值至少有一个Date条目。abstract booleaninclude(RowFilter.Entry<? extends M,? extends I> entry)如果指定的条目应该显示,则返回true; 如果条目应该隐藏,则返回false。static <M,I> RowFilter<M,I>notFilter(RowFilter<M,I> filter)如果提供的过滤器不包含条目,则返回一个包含条目的RowFilter。static <M,I> RowFilter<M,I>numberFilter(RowFilter.ComparisonType type, Number number, int... indices)返回一个RowFilter,其中包含符合指定条件的值至少有一个Number条目。static <M,I> RowFilter<M,I>orFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)返回一个RowFilter,如果任何提供的过滤器包含条目,则包含条目。static <M,I> RowFilter<M,I>regexFilter(String regex, int... indices)返回一个RowFilter,它使用正则表达式来确定要包括哪些条目。
-
-
-
方法详细信息
-
regexFilter
public static <M,I> RowFilter<M,I> regexFilter(String regex, int... indices)
返回一个RowFilter,它使用正则表达式来确定要包含的条目。 仅包含具有至少一个匹配值的条目。 例如,以下内容创建一个RowFilter,其中包含以“a”开头的至少一个值的条目:RowFilter.regexFilter("^a");返回的过滤器使用
Matcher.find()进行测试。 要测试完全匹配,使用字符'^'和'$'分别匹配字符串的开头和结尾。 例如,“^ foo $”仅包括其字符串完全为“foo”而不是“food”的行。 有关支持的正则表达式构造的完整说明,请参阅Pattern。- 参数类型
-
M-RowFilter适用的型号类型 -
I- 传递给RowFilter的标识符的类型 - 参数
-
regex- 要过滤的正则表达式 -
indices- 要检查的值的索引。 如果不提供,则评估所有值 - 结果
-
一个
RowFilter实现指定的标准 - 异常
-
NullPointerException- 如果regex是null -
IllegalArgumentException- 如果任何indices是<0 -
PatternSyntaxException- 如果regex不是有效的正则表达式。 - 另请参见:
-
Pattern
-
dateFilter
public static <M,I> RowFilter<M,I> dateFilter(RowFilter.ComparisonType type, Date date, int... indices)
返回一个RowFilter,其中包含符合指定条件的值至少有一个Date条目。 例如,以下RowFilter仅包含在当前日期之后至少有一个日期值的条目:RowFilter.dateFilter(ComparisonType.AFTER, new Date());- 参数类型
-
M-RowFilter适用的型号类型 -
I- 传递给RowFilter的标识符的类型 - 参数
-
type- 要执行的比较类型 -
date- 与之比较的日期 -
indices- 要检查的值的索引。 如果不提供,则评估所有值 - 结果
-
一个
RowFilter实现指定的标准 - 异常
-
NullPointerException- 如果date是null -
IllegalArgumentException- 如果任何indices是<0或type是null - 另请参见:
-
Calendar,Date
-
numberFilter
public static <M,I> RowFilter<M,I> numberFilter(RowFilter.ComparisonType type, Number number, int... indices)
返回一个RowFilter,其中包含符合指定条件的值至少有一个Number条目。 例如,以下过滤器将仅包含至少一个数值等于10的条目:RowFilter.numberFilter(ComparisonType.EQUAL, 10);- 参数类型
-
M-RowFilter适用的型号类型 -
I- 传递给RowFilter的标识符的类型 - 参数
-
type- 要执行的比较类型 -
number- 一个Number值进行比较 -
indices- 要检查的值的索引。 如果不提供,则评估所有值 - 结果
-
一个
RowFilter实现指定的条件 - 异常
-
IllegalArgumentException- 如果任何indices是<type是null或number是null
-
orFilter
public static <M,I> RowFilter<M,I> orFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)
返回一个RowFilter,如果任何提供的过滤器包含条目,则包含条目。以下示例创建一个
RowFilter,其中将包含任何包含字符串“foo”或字符串“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);- 参数类型
-
M-RowFilter适用的型号类型 -
I- 传递给RowFilter的标识符类型 - 参数
-
filters-RowFilter的测试 - 结果
-
一个
RowFilter实现指定的标准 - 异常
-
IllegalArgumentException- 如果任何一个过滤器是null -
NullPointerException- 如果filters为空 - 另请参见:
-
Arrays.asList(T...)
-
andFilter
public static <M,I> RowFilter<M,I> andFilter(Iterable<? extends RowFilter<? super M,? super I>> filters)
如果所有提供的过滤器都包含条目,则返回一个包含条目的RowFilter。以下示例创建一个
RowFilter,其中将包含包含字符串“foo”和字符串“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);- 参数类型
-
M-RowFilter适用的型号型号 -
I- 传递给RowFilter的标识符的类型 - 参数
-
filters- 要测试的RowFilter - 结果
-
一个
RowFilter实现指定的标准 - 异常
-
IllegalArgumentException- 如果任何一个过滤器是null -
NullPointerException- 如果filters为空 - 另请参见:
-
Arrays.asList(T...)
-
notFilter
public static <M,I> RowFilter<M,I> notFilter(RowFilter<M,I> filter)
如果提供的过滤器不包含条目,则返回一个包含条目的RowFilter。- 参数类型
-
M-RowFilter适用的型号类型 -
I- 传递给RowFilter的标识符的类型 - 参数
-
filter- 否定的RowFilter - 结果
-
一个
RowFilter实现指定的标准 - 异常
-
IllegalArgumentException- 如果filter是null
-
include
public abstract boolean include(RowFilter.Entry<? extends M,? extends I> entry)
如果指定的条目应该显示,则返回true; 如果条目应该隐藏,则返回false。entry参数仅在调用期间有效。 调用后使用entry返回结果导致未定义的行为。- 参数
-
entry- 一个非null对象,将模型中的底层对象包起来 - 结果
- true if the entry should be shown
-
-