tags:

views:

107

answers:

2
+1  Q: 

Java JList model

How can I make a list model from a JList in order to be able to insert an item into it. I want to use this method: addElement(java.lang.Object item)

I found an explanation here, but the problem is that ListModel is an interface and even if I write an implementation and override its method, I can't use the addElement() method

+3  A: 

Java provides implementations of ListModel already, like DefaultListModel, that you can instantiate and use

For example:

final DefaultListModel model = new DefaultListModel();
model.addElement("one");
model.addElement("two");
model.addElement("three");

final JList list = new JList(model);
Michael Mrozek
many thaaaaaaaaaaaaaaaaaaanxmay allah bless and guide
Alaa
@Alaa: In addition, an acceptable way to express thanks is to up-vote (orange triangle) or accept (green check) an answer.
trashgod
+1  A: 

Check out this Sun Tutorial. Contains example on how to add lists to a JList

npinti