views:

35

answers:

1

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?

+2  A: 

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.

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.

jackrabbit