使用 JTable 或 GlazedList 创建和使用多个过滤器/搜索

发布于 2024-08-09 00:40:35 字数 1493 浏览 4 评论 0原文

我查找了如何在此处使用常规表格使用多个过滤器,答案都指向 GlazedLists。但是,答案没有具体说明如何使用它。我能够让一个过滤器工作,但不知道如何让多个过滤器工作。 对于我使用的一个过滤器:

  // nameE is a BasicEventList containing classes (name) which 
  // contain the table values
  TextFilterList filtered = new TextFilterList(nameE);
  JTextField filterEdit = filtered.getFilterEdit();

  // Inside the table value class (name) there is a filter for myName
  public void getFilterStrings(List baseList) {
      baseList.add(myName);
  }

复制代码并创建另一个 JTextField 不起作用。我查了一下这个问题,它出现 CompositeMatcherEditor 可能有效。问题是我不知道如何实现这一点。

另外,我正在使用 Eclipse。我下载了 GlazedLists 1.8.0 并将其放入 Eclipse 中。但是,我无法使用它。我到处都是红色方块(源文件夹除外)!我什至添加了 jar 文件。

我希望我已经正确解释了自己。如果我需要扩展,请告诉我。

我的 Pastebin:姓名浏览器表格格式表模型

I looked up how to use multiple filters on here with a regular table and the answers all pointed to GlazedLists. However, the answers didn't specify how to use it. I was able to get one filter to work but do not know how to get more than one.
For one filter I used:

  // nameE is a BasicEventList containing classes (name) which 
  // contain the table values
  TextFilterList filtered = new TextFilterList(nameE);
  JTextField filterEdit = filtered.getFilterEdit();

  // Inside the table value class (name) there is a filter for myName
  public void getFilterStrings(List baseList) {
      baseList.add(myName);
  }

Duplicating the code and creating another JTextField does not work. I looked this problem up and it appears CompositeMatcherEditor may work. The problem is I do not know how to implement this.

Also, I am using Eclipse. I downloaded GlazedLists 1.8.0 and dropped it into Eclipse. However, I can't use it. I have red squares all over (except for the source folder)! I even added the jar file.

I hope I have explained myself correctly. Please let me know if I need to expand.

My Pastebin: Name, Browser, TableFormat, TableModel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟织青萝梦 2024-08-16 00:40:35

TextFilterList 已弃用 - 请参阅 javadocs - 但这是一个附带问题。

您可以在这里使用多种方法 - 如果您想要非常简单,那么只需将您的过滤器列表包装在另一个过滤器列表中:

EventList filtered = new FilterList(new FilterList(nameE, myFirstMatcherEditor), mySecondMatcherEditor);

更好的方法是使用多个匹配器编辑器来创建 CompositeMatcherEditor

EventList filtered = new FilterList(nameE, new CompositeMatcherEditor(myFirstMatcherEditor, mySecondMatcherEditor));

您可以使用 setMode 来控制编辑器是否使用 AND 组合或或行为。

以下是有关使用过滤器列表的必读信息

此处提供的截屏视频也值得花几分钟的时间。

TextFilterList is deprecated - see the javadocs - but that's a side issue.

There are several approaches you can use here - if you want really simple, then just wrap your filter list in another filter list:

EventList filtered = new FilterList(new FilterList(nameE, myFirstMatcherEditor), mySecondMatcherEditor);

A better way is to use multiple matcher editors to create a CompositeMatcherEditor:

EventList filtered = new FilterList(nameE, new CompositeMatcherEditor(myFirstMatcherEditor, mySecondMatcherEditor));

you can use setMode to control whether your editors are combined using AND or OR behavior.

Here's Must Read info on using filter lists.

The screencasts available here are also worth the few minutes investment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文