Java Utililty Methods JList Model

List of utility methods to do JList Model

Description

The list of methods to do JList Model are organized into topic(s).

Method

voidadd(final DefaultListModel model, final Collection collection)
add
model.clear();
for (Iterator<Object> iterator = collection.iterator(); iterator.hasNext();) {
    model.addElement(iterator.next());
voidaddAll(DefaultListModel m, List o)
Adds all Elements from a List to a DefaultListModel
for (int i = 0; i < o.size(); i++) {
    m.addElement(o.get(i));
booleancanHandleModel(JList list)
Returns whether the list model can be handled.
return (list.getModel() instanceof DefaultListModel);
ListModelcollectionListModel(Collection collection)
Returns a list model of the specified collection.
DefaultListModel model = new DefaultListModel();
for (Iterator i = collection.iterator(); i.hasNext();)
    model.addElement(i.next());
return model;
DefaultListModelcreateDefaultListModel(final Object... elements)
create Default List Model
final DefaultListModel model = new DefaultListModel();
for (Object o : elements)
    model.addElement(o);
return model;
JListcreateList(final ListModel model)
create List
@SuppressWarnings("unchecked")
JList lst = new JList(model);
if (isMacOS_10_5_X) {
    lst.putClientProperty("JComboBox.isPopDown", Boolean.TRUE);
return lst;
DefaultListModelgenerateListModel()
generate List Model
return new DefaultListModel();
DefaultListModelgetDefaultListModel(JList list)
Get the DefaultListModel from JList.
return (DefaultListModel<T>) list.getModel();
DefaultListModelgetListModel()
get List Model
return linkListModel;
DefaultListModelgetListModel(T[] data)
creates a DefaultListModel from an Array
DefaultListModel<T> lm = new DefaultListModel<T>();
for (T t : data) {
    lm.addElement(t);
return lm;