• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Notify ObservableList Listeners of a Change in One of Its Elements

 
Mike Matthews
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,

I want objects listening to changes in my ObservableList to be notified of changes in one of its elements without needing to remove the element and add a new one in its place. I hope I make myself clear. Right now, to trigger change event, I need to write the code as follows (create a tempItem):

 
John Damien Smith
Ranch Hand
Posts: 296
14
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use an extractor to register for update notifications on the properties of the item that you want to listen to updates on.

Here is a sample:



Sample Output:



Note that the update notification is received, when the description of the apple changed from Green Skin to Red Skin as the apple ripened. Without an extractor definition, this update notification would not be received.
 
Mike Matthews
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,

Thank you kindly for your reply. I already solved the problem using exactly this solution (extractor.) It worked perfectly. I added the extractor() method to my Item class so now it looks as follows:


I used ListProperty<Item> to store items. Hopefully it will help someone else in the future.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic