Here you can find the source of removeItemJList(javax.swing.JList jlist)
public static void removeItemJList(javax.swing.JList jlist)
//package com.java2s; /*//from w w w . j a v a2 s . 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 removeItemJList(javax.swing.JList jlist) { String id = (String) jlist.getSelectedValue(); if (id != null) { int size = jlist.getModel().getSize(); if (size == 0) return; String[] ary = new String[size - 1]; int cnt = 0; for (int i = 0; i < size; i++) { String s = (String) jlist.getModel().getElementAt(i); if (s.contains(id)) ; // skip the item else ary[cnt++] = (String) jlist.getModel().getElementAt(i); } jlist.setModel(new javax.swing.DefaultComboBoxModel(ary)); } } }