Here you can find the source of fillList(Object[] elements, JList list)
Parameter | Description |
---|---|
anList | List |
anJList | JList |
public static void fillList(Object[] elements, JList list)
//package com.java2s; //License from project: Open Source License import javax.swing.*; public class Main { /**//from w w w .j av a 2 s . c o m * fillList * * @param anList List * @param anJList JList */ public static void fillList(Object[] elements, JList list) { setListModel(generateListModel(elements), list); } /** * fillList * * @param anList List * @param anJList JList */ public static void fillList(Iterable<?> elements, JList list) { setListModel(generateListModel(elements), 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(); } }