Java JList clearList(JList list)

Here you can find the source of clearList(JList list)

Description

fillList

License

Open Source License

Parameter

Parameter Description
anList List
anJList JList

Declaration

public static void clearList(JList list) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.*;

public class Main {
    /**// w ww.j a  v a  2s  .  c  om
     * fillList
     *
     * @param anList List
     * @param anJList JList
     */
    public static void clearList(JList list) {
        setListModel(generateListModel(), list);
    }

    private static void setListModel(ListModel model, JList list) {
        list.setModel(model);
        if (model.getSize() > 0) {
            list.setSelectedIndex(0);
        }
    }

    private static ListModel generateListModel(Object[] elements) {
        DefaultListModel listModel = new DefaultListModel();
        if (elements != null) {
            for (Object o : elements) {
                listModel.addElement(o);
            }
        }
        return listModel;
    }

    private static DefaultListModel generateListModel(Iterable<?> elements) {
        DefaultListModel listModel = generateListModel();
        if (elements != null) {
            for (Object o : elements) {
                listModel.addElement(o);
            }
        }
        return listModel;
    }

    private static DefaultListModel generateListModel() {
        return new DefaultListModel();
    }
}

Related

  1. applyDefaultProperties(final JList comp)
  2. ensureCustomBackgroundStored(JList comp)
  3. ensureRangeIsVisible(JList list, int top, int bottom)
  4. filterDataList(JList jList, List dataList, String text)
  5. getStoredBackground(JList comp)