Java JList Add Remove addItemJList(javax.swing.JList jlist, String item)

Here you can find the source of addItemJList(javax.swing.JList jlist, String item)

Description

add Item J List

License

Open Source License

Declaration

public static void addItemJList(javax.swing.JList jlist, String item) 

Method Source Code

//package com.java2s;
/*//from   w  w  w .ja  v  a 2s .c  o m
 * @(#)RunUtilFunc.java   
 *
 * Copyright (C) 2006-2007 www.interpss.org
 *
 * This program 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 program 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 General Public License for more details.
 *
 * @Author Mike Zhou
 * @Version 1.0
 * @Date 12/15/2007
 * 
 *   Revision History
 *   ================
 *
 */

public class Main {
    public static void addItemJList(javax.swing.JList jlist, String item) {
        int size = jlist.getModel().getSize();
        String[] ary = new String[size + 1];
        for (int i = 0; i < size; i++) {
            ary[i] = (String) jlist.getModel().getElementAt(i);
        }
        ary[size] = item;
        jlist.setModel(new javax.swing.DefaultComboBoxModel(ary));
    }
}

Related

  1. addDoubleClickEvent(JList list)
  2. addToList(JList list, Object object)
  3. fillList(Collection anList, JList anJList)
  4. fillList(JList aListComponent, String theList, boolean removeQuotes)
  5. fillList(Object[] elements, JList list)