• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clearing a JList

 
Carlos Delgado
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!
I want to clear all the items of the list because depending on the option the user chooses I'm showing one kind of information or another.
I'm trying list.removeAll(). It doesn't work.
With the DefaultListModel associated to the JList I'm trying:
listModel.clear();
listModel.removeAllElements();
Even I'm trying to delete each element manually with listModel.removeElementAt(index);
These 3 statements crash if one element of the list is selected. I want to know if there's a way of clearing the list or deselecting the selected item...

Thanks!
 
Pat Hays
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code is here

jList1.setListData(new Object[0]);
[ August 20, 2004: Message edited by: Pat Hays ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
listModel.clear() works OK to remoave all elements
list.clearSelection() is the other one you need

try this

 
Carlos Delgado
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying! I actually got it working now!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic