Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JcomboBox multiple selection

I have a jcombobox in my application. and i want it to support multiple selection (like it do in a jlist). is there any code example?

like image 714
Adi Mor Avatar asked Dec 12 '11 08:12

Adi Mor


1 Answers

I think it's not possible, unless you use a JList, like you said.

The JComboBox API reports:

The user can select a value from the drop-down list, which appears at the user's request.

And a JComboBox tutorial:

Lists are not terribly attractive, but they're more appropriate than combo boxes when the number of items is large (say, over 20) or when selecting multiple items might be valid.

Update:

I reviewed this answer, because actually it's "possible" to do that using a ListCellRenderer, adding a checkbox to each item. Please consider this answer to implement this "solution".

However, I don't think it's a good idea for the following reasons:

  1. there's a control like a JList that allows multiple selection;
  2. a JComboBox control is designed just for single item selection;
  3. it doesn't make sense to me to still use a JComboBox control and allow a multiple selection.
like image 172
Alberto Solano Avatar answered Nov 11 '22 06:11

Alberto Solano