DefaultListModel remove Item - Java Swing

Java examples for Swing:JList

Description

DefaultListModel remove Item

Demo Code


//package com.java2s;

import javax.swing.DefaultListModel;

public class Main {
    public static DefaultListModel<String> removeItem(
            DefaultListModel<String> listModel, int SelectedIndex) {
        // Check if selected index is in bounds.
        if (SelectedIndex >= 0) {
            // Remove the selected item.
            listModel.removeElementAt(SelectedIndex);
        }/*  w  ww.  j  a  v a2s .c  om*/
        return listModel;
    }
}

Related Tutorials