• Post Reply Bookmark Topic Watch Topic
  • New Topic

Clearing a JList  RSS feed

 
murat tasova
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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());
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Since JList is a Swing class, this thread will sit better in the Swing forum . . . moving.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!