Java JList Select removeSelectedListItems(JList sourceList)

Here you can find the source of removeSelectedListItems(JList sourceList)

Description

remove Selected List Items

License

Open Source License

Declaration

public static void removeSelectedListItems(JList sourceList) 

Method Source Code

//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);
            }
        }
    }
}

Related

  1. JListRemoveSelectedObject(javax.swing.JList list)
  2. linkEnabledToSelected(final JComponent component, final ListSelectionModel model)
  3. moveSelectedItems(JList list, int nrRows)
  4. moveSourceSelection(JList sourceList, boolean moveDown, boolean byPage)
  5. removeListSelectionListeners(final JList comp)
  6. removeSelectionFromList(JList fileList)
  7. removeTypeSelectionListener(JList list)
  8. selectByTyping(javax.swing.JList list, javax.swing.JTextField textfield)
  9. selectRow(int row, ListSelectionModel model)