Here you can find the source of clearList(JList list)
Parameter | Description |
---|---|
anList | List |
anJList | JList |
public static void clearList(JList list)
//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(); } }