在Java中过滤Combobox数据

编程入门 行业动态 更新时间:2024-10-10 11:27:28
本文介绍了在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数据

本文发布于:2023-11-13 04:33:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583438.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   Java   Combobox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!