How to create a drop-down list in java swing with multiple item selection?

K_U picture K_U · May 18, 2010 · Viewed 37.4k times · Source

I'm aware of JList and JComboBox. I need the combo box drop down functionality with multiple selection functionality that JList provides.

This is because the contents of the list are too huge to be displayed using a simple list. I also need to select multiple items, otherwise I would have been content with JComboBox.

Any suggestions?

Answer

Nate picture Nate · May 18, 2010

When using multi-select, it's better to use a list than a combo box. As GUI metaphors go, people expect a combo box to be single select, whereas lists can be either.

the contents of the list are too huge to be displayed using a simple list

Place the JList in a JScrollPane. You can call setVisibleRowCount(int) on the JList to specify how many rows at a time should be shown.