Java JList Select JListRemoveSelectedObject(javax.swing.JList list)

Here you can find the source of JListRemoveSelectedObject(javax.swing.JList list)

Description

J List Remove Selected Object

License

CDDL license

Declaration

public static void JListRemoveSelectedObject(javax.swing.JList list) 

Method Source Code

//package com.java2s;
/*//from w  ww  .  j  a v  a2s.c om
Copyright (c) 2013 eBay, Inc.
This program is licensed under the terms of the eBay Common Development and
Distribution License (CDDL) Version 1.0 (the "License") and any subsequent  version 
thereof released by eBay.  The then-current version of the License can be found 
at http://www.opensource.org/licenses/cddl1.php and in the eBaySDKLicense file that 
is under the eBay SDK ../docs directory.
*/

public class Main {
    public static void JListRemoveSelectedObject(javax.swing.JList list) {
        Object sel = list.getSelectedValue();
        if (sel != null) {
            javax.swing.ListModel lm = list.getModel();
            Object[] newList = new Object[lm.getSize() - 1];
            int cur = 0;
            for (int i = 0; i < lm.getSize(); i++) {
                if (lm.getElementAt(i) != sel)
                    newList[cur++] = lm.getElementAt(i);
            }
            list.setListData(newList);
        }
    }
}

Related

  1. getSelectedIndecies(final ListSelectionModel lsm)
  2. getSelectedItems(DefaultListModel listModel, ListSelectionModel selectionModel)
  3. getSelectedMultipleList(JList anJList)
  4. getSelectedRows(ListSelectionModel listSelectionModel)
  5. initParamList(final JList paramList, final String[] availNames, final String[] defaultSelection)
  6. linkEnabledToSelected(final JComponent component, final ListSelectionModel model)
  7. moveSelectedItems(JList list, int nrRows)
  8. moveSourceSelection(JList sourceList, boolean moveDown, boolean byPage)
  9. removeListSelectionListeners(final JList comp)