• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

updating view based on model changes automatically

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
His,

Can't seem to find a straightforward way to have a JList updating its view when the datamodel it is bound to changes.

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?

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.

Many thanks.
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic