Java Swing Updating JList?

Updates should be made to the ListModel, not the Array that was used to create the model.

Updates should be made to the ListModel, not the Array that was used to create the model. However, if you want to refresh the list with completely new items or change the order of the items then you create a new DefaultListModel and use the setModel(...) method of the JList to update the view.

Thanks. When adding items to the DefaultListmMdel, do I have to use a for loop or can I pass in an array or Vector? – GLRockwell Dec 5 '09 at 5:41 Actually I keep forgetting the DefaultListModel doesn't accept an Array or Vector, so yes you would need to add each item individually.

However, the DefaultComboBoxModel does accept an Array or Vector and it implements ListModel so you can use it instead. – camickr Dec 5 '09 at 6:31 Would the following code work? It doesn't seem to be displaying properly.

Public void updateLibrary(){ DefaultListModel dlm = new DefaultListModel(); //Display library items for(int l = 0; l SetModel(dlm); } – GLRockwell Dec 5 '09 at 7:04 That's horribly formatted, sorry. The code can be seen here: pastebin. Com/m52633f36 – GLRockwell Dec 5 '09 at 7:07 Yes, this works.

The problem lies elsewhere. Thanks. – GLRockwell Dec 5 '09 at 7:42.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions