Here you can find the source of removeSelectedListItems(JList sourceList)
public static void removeSelectedListItems(JList sourceList)
//package com.java2s; import javax.swing.DefaultListModel; import javax.swing.JList; public class Main { public static void removeSelectedListItems(JList sourceList) { int sItemSelectedIndex = sourceList.getSelectedIndex(); Object[] sItemSelectedValues = sourceList.getSelectedValues(); DefaultListModel selectedTableListModel = (DefaultListModel) sourceList .getModel();/*from ww w .ja v a 2s.com*/ if (selectedTableListModel.size() > 0) { for (int i = sItemSelectedValues.length - 1; i >= 0; i--) { selectedTableListModel .removeElement(sItemSelectedValues[i]); } } if (sItemSelectedIndex >= 0) { if (sItemSelectedIndex >= selectedTableListModel.size()) { sourceList .setSelectedIndex(selectedTableListModel.size() - 1); } else { sourceList.setSelectedIndex(sItemSelectedIndex); } } } }