Here you can find the source of getSelectedItems(DefaultListModel
static <T> List<T> getSelectedItems(DefaultListModel<T> listModel, ListSelectionModel selectionModel)
//package com.java2s; //License from project: GNU General Public License import javax.swing.DefaultListModel; import javax.swing.ListSelectionModel; import java.util.ArrayList; import java.util.List; public class Main { static <T> List<T> getSelectedItems(DefaultListModel<T> listModel, ListSelectionModel selectionModel) { int iMin = selectionModel.getMinSelectionIndex(); int iMax = selectionModel.getMaxSelectionIndex(); final ArrayList<T> itemList = new ArrayList<>(); if (iMin < 0 || iMax < 0) { return itemList; }//w w w.j a va 2 s. co m for (int i = iMin; i <= iMax; i++) { if (selectionModel.isSelectedIndex(i)) { itemList.add(listModel.get(i)); } } return itemList; } }