Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 694
K_U Avatar asked May 18 '10 19:05

K_U


People also ask

How do I select multiple selections in dropdown?

Windows: We need to hold down the CTRL button to select multiple options. Mac: We need to hold down the command button to select multiple options.

How do you create a drop down list in Java Swing?

Create a Dropdown Menu Using JComboBox in Java swing package and is used to show a dropdown list in an interface. Below, we first create the array of options to display in the dropdown list. JComboBox is a component and needs a frame to reside, so we create a JFrame object.

How do I select multiple items in a ComboBox?

Select the items in ComboBox You can select multiple items at one shot in MultiSelectionComboBox by using ShowCheckBox and DisplayMode property.

How many multiple options can be selected in dropdown?

To select multiple options in a drop-down list, use the multiple properties. It allows you to select more than one option while pressing CTRL key.


1 Answers

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.

like image 107
Nate Avatar answered Oct 05 '22 20:10

Nate