* Returns all selected items.
*
* @return an array containing all the selected items
*/
public Object[] getSelectedValues() {
ListModel model = getModel();
int min = getMinSelectedIndex();
if (min == -1) {
// No values are selected, return empty array.
return new Object[0];
}
int selectionCount = 0;
int max = getMaxSelectedIndex();
int size = model.size();
if (max >= size - 1) {
max = size - 1;
}
for (int index = min; index <= max; ++index) {
if (isSelectedIndex(index)) {
++selectionCount;
}
}
Object[] selectedValues = new Object[selectionCount];
selectionCount = 0;
for (int index = min; index <= max; ++index) {
if (isSelectedIndex(index)) {
selectedValues[selectionCount] = model.get(index);
++selectionCount;
}
}
return selectedValues;