Java JList Add Remove removeFromList(JList list, Object object)

Here you can find the source of removeFromList(JList list, Object object)

Description

remove From List

License

LGPL

Declaration

public static void removeFromList(JList list, Object object) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import javax.swing.*;

public class Main {
    public static void removeFromList(JList list, Object object) {
        ListModel model = list.getModel();
        if (model == null) {
            model = new DefaultListModel();
            list.setModel(model);/*from ww w  .ja v a 2  s. com*/
        }
        ;
        if (model instanceof DefaultListModel) {
            DefaultListModel listModel = (DefaultListModel) model;
            listModel.removeElement(object);
        }
    }

    public static void removeFromList(JList list, int index) {
        ListModel model = list.getModel();
        if (model == null) {
            model = new DefaultListModel();
            list.setModel(model);
        }
        ;
        if (model instanceof DefaultListModel) {
            DefaultListModel listModel = (DefaultListModel) model;
            listModel.removeElementAt(index);
        }
    }
}

Related

  1. fillList(Collection anList, JList anJList)
  2. fillList(JList aListComponent, String theList, boolean removeQuotes)
  3. fillList(Object[] elements, JList list)
  4. JListAddObject(javax.swing.JList list, Object item)
  5. removeAllListItems(JList sourceList)
  6. removeItemJList(javax.swing.JList jlist)