how-to

Window (swing) applications

How to clear all items from JList

For deleting all items in typical list javax.swing.JList use this techniques.

VARIANT 1

Create new empty DefaultListModel model and set it to list.

DefaultListModel m = new DefaultListModel();  // 
    
list1.setModel( m );

VARIANT 2

Create new empty AbstractListModel by JList.setListData() method.

list1.setListData( new Object[0] );