• 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: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there,

I just don't get de jlist clear. After an event I just wan't to empty the Jlist. But somehow dlm.removeAllElements() does not clear the JList.

What do I forget people?


declaration :
private DefaultListModel dlm = new DefaultListModel();

defining the StoelenjList:
StoelenjList.setModel(dlm);
StoelenjList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);


add elements to the JList in a for lus :
dlm.addElement(s.toString());
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Since JList is a Swing class, this thread will sit better in the Swing forum . . . moving.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dlm.removeAllElements() should work
you could also try
dlm.clear()

but if still not working, you've possibly declared dlm twice,
once as a class field (in your post), also where you load the model,
so the one referenced from your listener is not the same as the one with the elements
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic