I faced a problem with this setSelectedValue() method in JList when I wanted to select multiple values in a JList automatically, it still selected only one. Is there a way?
String[] items = { "Item 1", "Item 2", "Item 3", "Item 4" };
final JList theList = new JList(items);
theList.setSelectedValue("Item 1",true);
theList.setSelectedValue("Item 2",true);
This code shows only Item 2 as selected.
Use
JList.setSelectedIndices(int[])after callingJList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION).E.G.
Screen Shot