在Java中过滤Combobox数据 [英] Filter Combobox Data in Java

查看:264
本文介绍了在Java中过滤Combobox数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在java中,让我们说有两个jpanels,当我点击Panle'1'上的按钮'A',它将显示面板'2'。在面板'2',有两个组合框和我完成了所有必要的编码。但有一件事要过滤是combobox'1'将只显示那些有书前缀的数据。 &组合框'2'将只显示那些没有'书前缀'。

In java, let's say there are two jpanels, when I click button 'A' on Panle'1', it will show panel '2'. In panel '2', there are two comboboxes and I finished all necessary coding. But one thing to filter is combobox'1' will show only those data who has 'book'prefix. & combobox '2' will show only those without 'book prefix'. How should I filter it?

推荐答案

ComboBoxModel 您的 JComboBox 。我知道的唯一的过滤方式是在模型中没有不需要的值。您可以在创建模型时过滤它们。

The ComboBoxModel controls the content of your JComboBox. The only way to filter that I know of is to not have the unwanted values in your models. You can filter them out when creating the models.

假设您在列表中具有所有所需的值,将使用 GlazedLists 库。它提供了可观察的列表,并让你做他们的各种有趣的东西,如过滤和排序。在这种情况下特别感兴趣的是 FilterList :你提供 EventList Matcher ,它决定如何过滤EventList。 FilterList类似于EventList的视图,这意味着如果您更改EventList,FilterList将反映这一点。使用这个FilterList,你可以创建一个 EventComboBoxModel 并使用它作为你的模型。

Assuming you have all the desired values in a List, I would use the GlazedLists library. It provides observable lists and lets you do all kinds of interesting stuff with them, like filtering and sorting. Of particular interest in this case is FilterList: you supply it an EventList and a Matcher which decides how to filter the EventList. The FilterList acts like a view on the EventList, meaning that if you change the EventList, the FilterList will reflect this. With this FilterList, you can then make a EventComboBoxModel and use that as your model.

这篇关于在Java中过滤Combobox数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆