Here you can find the source of addItemJList(javax.swing.JList jlist, String item)
public static void addItemJList(javax.swing.JList jlist, String item)
//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)); } }