Java examples for Swing:JList
fill Collection to JList
//package com.java2s; import java.util.*; import javax.swing.*; public class Main { /**//www.j a v a2s. 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); } } }