• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Clearing a JList

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code is here

jList1.setListData(new Object[0]);
[ August 20, 2004: Message edited by: Pat Hays ]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying! I actually got it working now!
 
reply
    Bookmark Topic Watch Topic
  • New Topic