Removing items from JList

前端 未结 6 1110
野性不改
野性不改 2021-01-01 05:26

I\'ve got a simple Jlist with data from List, Now I want to remove selected item from Jlist. Here is the code:

final DefaultListMo         


        
6条回答
  •  清歌不尽
    2021-01-01 05:47

    According to the javadoc, using remove() instead of removeElementAt() is recommended, so :

    public void actionPerformed(ActionEvent arg0) {
        int index = list.getSelectedIndex();
        if (index != -1) {
            model.remove(index);
    }
    

提交回复
热议问题