1

I'm developing an app which involves a UI displaying a list of elements. Each element is characterised by an amount of votes.

I would like to listen to any changes that affect the list so I can update the UI. For example, I have the three following elements:

Element e1 = new Element(2);  //  2 votes.
Element e2 = new Element(5);  //  5 votes.
Element e3 = new Element(-3); // -3 votes.

My list will be the following after the initialization: [e2, e1, e3]. Let's say I downvote e1, so the list stays the same but I want my UI to know that an element has been modified.

I've searched for a solution but couldn't find one. I bet someone has already had this issue before. Any ideas/libraries/... to offer?

Many thanks in advance!

faku
  • 411
  • 4
  • 19
  • 2
    [this might help you get started](http://stackoverflow.com/questions/28449809/why-are-there-no-observablequeues-in-javafx), the guy shows how to create an `ObservableQueue` – Flika205 May 01 '17 at 17:41
  • Possible duplicate (or at least related): [Callback and extractors for JavaFX ObservableList](http://stackoverflow.com/questions/31687642/callback-and-extractors-for-javafx-observablelist) – jewelsea May 01 '17 at 23:08
  • It's not useful to observe the contents of a `PriorityQueue`, since the contents aren't kept in sorted order. It'd probably be more fruitful to pursue an approach where elements of an `ObservableList` are kept in sorted order. – Stuart Marks May 02 '17 at 05:25

0 Answers0