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

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

Description

add To List

License

LGPL

Declaration

public static void addToList(JList list, Object object) 

Method Source Code

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

import javax.swing.*;

public class Main {
    public static void addToList(JList list, Object object) {
        ListModel model = list.getModel();
        if (model == null) {
            model = new DefaultListModel();
            list.setModel(model);//from w w w . ja  v  a 2 s  . c  om
        }
        ;
        if (model instanceof DefaultListModel) {
            DefaultListModel listModel = (DefaultListModel) model;
            listModel.addElement(object);
        }
    }
}

Related

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