69.0k views
2 votes
How can multiple items be selected at the same time in aJList?

User Amer Sawan
by
7.9k points

1 Answer

6 votes

Answer:

JList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION)

Step-by-step explanation:

JList provides for simultaneous selection of multiple items upon setting the selection mode to MULTIPLE_INTERVAL_SELECTION. The API call for this purpose is:

jlist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION)

Once the selection mode has been set , we can select set of items in the list as follows:

jlist.setSelectedIndices({1,3,5});

This will select the items with indices 1,3,5 in the list.

User Taneisha
by
7.3k points

No related questions found