You can add elements to a list by just passing it a Vector
in the constructor or using the setListData
method, but that is not the best way to do it.
You would usually want to use a ListModel
implementation like DefaultListModel
. It defines methods for handling data (addElement
, removeElement
,...).
You could reduce the amount of exchanged data between the server and the client(s) by querying the server for the removed element only and not getting all the data.
Update: Now I see you are using a model. The default implementation of a JList
model is not of type DefaultListModel
. You can set the model in the JList
constructor, when you instantiate your JList
at the beginning.
DefaultListModel model = new DefaultListModel();
JList list = new JList(model);
Don't instantiate it again, you need to do that only once. Then, you can use the code you posted, but you don't have to call the setModel()
method after you remove an element.