Java JComboBox Item setListData(JComboBox box, Object[] items)

Here you can find the source of setListData(JComboBox box, Object[] items)

Description

Procedure to set the list of items in a ComboBox

License

Open Source License

Parameter

Parameter Description
box Combobox to fill
items Items to add

Declaration

public static void setListData(JComboBox box, Object[] items) 

Method Source Code

//package com.java2s;
/*//  w ww  .j  a v  a2  s.co m
 * Copyright 1997-2016 Unidata Program Center/University Corporation for
 * Atmospheric Research, P.O. Box 3000, Boulder, CO 80307,
 * support@unidata.ucar.edu.
 * 
 * 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; either version 2.1 of the License, or (at
 * your option) any later version.
 * 
 * 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.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

import java.util.List;

import javax.swing.JComboBox;

public class Main {
    /**
     * Procedure to set the list of items in a ComboBox
     *
     * @param box Combobox to fill
     * @param items Items to add
     */
    public static void setListData(JComboBox box, Object[] items) {
        box.removeAllItems();
        if (items != null) {
            for (int i = 0; i < items.length; i++) {
                box.addItem(items[i]);
            }
        }
    }

    /**
     * Procedure to set the list of items in a ComboBox
     *
     * @param box Combobox to fill
     * @param items Items to add
     */
    public static void setListData(JComboBox box, List items) {
        box.removeAllItems();
        if (items != null) {
            for (int i = 0; i < items.size(); i++) {
                box.addItem(items.get(i));
            }
        }
    }
}

Related

  1. makeComboBox(Object[] items)
  2. replaceComboContents(JComboBox cb, String[] items)
  3. replaceComboItems(JComboBox combo, Vector items)
  4. selJComboBoxItem(Properties properties, JComboBox combo, Vector namVec, String name)
  5. selJComboBoxItem(Properties properties, JComboBox combo, Vector namVec, String name)