Originally posted by Denis Wen:
Can't seem to find a straightforward way to have a JList updating its view when the datamodel it is bound to changes.
This strikes me as an odd thing to say. With DefaultListModel, for example, calling add*(), clear(), copyInto(), insertElementAt(), remove*(), or set*() will fire a ListDataEvent to all listeners. The JList updates itself because it has registered as a listener.
Right now I build a String[] (A) array from a more complicated List of objects (B). The way I see it, is that when this array is changed the view should change automatically. A listener of some kind, but I am quite new in this stuff?
Well what is the relationship between your String[] (A) array and your ListModel?
Also what would be a way to update the base model everytime the underlining data source changes. I am using in-memory cache, and would like to update List B and sequentially array A everytime the underlining data changes.
It really depends on the details. One thing to consider is to not mess with this intermediate List A at all, and have your more complicated list of objects (B) inherit from AbstractListModel or otherwise implement the ListModel interface. You would still have to fire off the events, but you wouldn't have to deal with an intermediate List.