List to JList ListModel - Java Swing

Java examples for Swing:JList

Description

List to JList ListModel

Demo Code


//package com.java2s;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.swing.AbstractListModel;

import javax.swing.ListModel;

public class Main {
    public static ListModel toListModel(final List elements) {
        return (new AbstractListModel() {
            public int getSize() {
                return (elements.size());
            }// w ww . j a  va 2 s .c o  m

            public Object getElementAt(int index) {
                return (elements.get(index));
            }
        });
    }

    public static ListModel toListModel(Collection elements) {
        return (toListModel(new ArrayList(elements)));
    }
}

Related Tutorials