I’m making a swing based application where I have a JList that periodically get’s updated with different orderings of the same data, gets infrequently updated with new items, and also infrequently updated with less items. I’m trying to figure out the best way to make this look good. Right now, I just call
JList.setListData(String [] data);
Which doesn’t look too great, and it clears the selected items.
I want a way to update it that only clears the selected items if it was removed from the list, but otherwise keeps the same items selected, even if their index changes. I was looking into keeping track of which indexs are selected and then setting the selected items after changing the data but that sounds horrible. I also looked at ListModels and keeping track of my own but it seems that which items are selected is kept in the JList itself so that wouldn’t work perfectly either.
I’d really appreciate any suggestions.
I made you a working example.
I’ve used the
JListlike you requested, added buttons that resort, add, and delete from the list.Anyways, hope this helps!
Cheers.