Hi all
I want to add/append rows to a Jlist keeping the existing rows. How do I do that ? How do I update a certain row in a Jlist?
I appritiate your help!
Thank you in advance!
Y
vimal
Printable View
Hi all
I want to add/append rows to a Jlist keeping the existing rows. How do I do that ? How do I update a certain row in a Jlist?
I appritiate your help!
Thank you in advance!
Y
vimal
try this:
jlist.getModel().addElement(object);
Just like JTree and JTable, you don't manipulate the JList directly; instead, you manipulate its model. Look at the DefaultListModel class. It has the features you are looking for.
Look at the DefaultListModel. Adding rows is easy, but you must fire an event to update the list model.
The methods to fire change events are protected if I remember correctly. Because of this, you will
have to subclass DefaultListModel so that when you add elements to it you can also fire the change
event.
You can store the data in the vector and populate the JList though it. Every time you want to add new elements, add those into the vector and after removing the elements from the JList, populate it again.
May this will help you.
Try with this:
jList.setModel(new DefaultListModel());
((DefaultListModel)jList.getModel()).addElement(object);