Java JList Model toListModel(final List elements)

Here you can find the source of toListModel(final List elements)

Description

to List Model

License

Open Source License

Declaration

public static ListModel toListModel(final List elements) 

Method Source Code

//package com.java2s;
/*/*  w w w  .  ja va 2  s . com*/
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2003-2008, Open Source Geospatial Foundation (OSGeo)
 *        
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

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());
            }

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

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

Related

  1. removeAll(DefaultListModel m, List o)
  2. removeFromList(String path, DefaultListModel model, JList list)
  3. setListModel(ListModel model, JList list)
  4. toDefaultListModel(ArrayList list)
  5. toList(ListModel model)