user257065 user257065 - 4 months ago 53
Java Question

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

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

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.

Comments