DefaultListModel: clear() : DefaultListModel « javax.swing « Java by API






DefaultListModel: clear()

  


import javax.swing.DefaultListModel;
import javax.swing.JList;

public class Main {
  public static void main(String[] argv) throws Exception {
    DefaultListModel model = new DefaultListModel();
    JList list = new JList(model);

    // Remove the first item
    int pos = 0;
    model.remove(pos);

    // Remove the last item
    pos = model.getSize() - 1;
    if (pos >= 0) {
      model.remove(pos);
    }

    // Remove all items
    model.clear();
  }
}

   
    
  








Related examples in the same category

1.DefaultListModel: add(int index, Object element)
2.DefaultListModel: addElement(Object obj)
3.DefaultListModel: getSize()
4.DefaultListModel: insertElementAt(Object obj, int index)
5.DefaultListModel: remove(int index)
6.DefaultListModel: removeAllElements()
7.DefaultListModel: removeElementAt(int index)
8.DefaultListModel: removeRange(int fromIndex, int toIndex)
9.DefaultListModel: set(int index, Object element)
10.DefaultListModel: setElementAt(Object obj, int index)
11.JList: setFixedCellWidth(int width)
12.DefaultListModel: ensureCapacity(int count)