Java JList Add Remove fillList(Collection anList, JList anJList)

Here you can find the source of fillList(Collection anList, JList anJList)

Description

fillList

License

LGPL

Parameter

Parameter Description
anList List
anJList JList

Declaration

public static void fillList(Collection anList, JList anJList) 

Method Source Code


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

import java.util.*;

import javax.swing.*;

public class Main {
    /**/*from w  w w .ja va 2s.  c o  m*/
     * fillList
     *
     * @param anList List
     * @param anJList JList
     */
    public static void fillList(Collection anList, JList anJList) {
        DefaultListModel listModel = new DefaultListModel();
        if (anList != null && anJList != null) {
            Object el = null;
            Iterator it = anList.iterator();
            while (it.hasNext()) {
                el = it.next();
                listModel.addElement(el);
            }
        }
        anJList.setModel(listModel);
        if (listModel.size() > 0) {
            anJList.setSelectedIndex(0);
        }
    }
}

Related

  1. addDoubleClickEvent(JList list)
  2. addItemJList(javax.swing.JList jlist, String item)
  3. addToList(JList list, Object object)
  4. fillList(JList aListComponent, String theList, boolean removeQuotes)
  5. fillList(Object[] elements, JList list)
  6. JListAddObject(javax.swing.JList list, Object item)
  7. removeAllListItems(JList sourceList)