1

I am using a ObservableMap for data modeling, and want to update the whole entry. Initially the ObservableMap is empty, and it is filled asynchronously with lots of elements.

Now the problem is that an onChanged event is shot for each and every entry, which creates too many events and a bogging down of the GUI. I used pkgs.clear() ; pkgs ++= newpkgs.

Is there way to either only trigger one onChanged, either by disabling the handler temporarily, or by having an operation on the map that updates all elements but fires only afterwards.

Norbert Preining
  • 237
  • 1
  • 11

1 Answers1

1

I'm not aware of a mechanism to disable/delay/buffer UI updates.

I don't know about other JavaFX view types, but I have experience with this using TableView in a similar situation. I suspect other views may be similar in this regard.

At least the TableView has a property called itemsProperty. When data in itemsProperty is updated using setItems (wrapper for itemsProperty.set(value)), the table tries very hard to update just the minimum slice of it self.

However, for the optimizations to work, the key is that the items must be "value objects" (hashCode and equals are deep and based on the actual data being displayed and not some random references.)

In the case of TableView this may require elaborate rowFactory and cellFactory implementations. The reason is that the data in items can't be "preformatted" in any way or it would spoil the optimizations inside TableView.

Realizing the above, solved my update churn problems. Maybe other answers can provide other tips.

Peter Lamberg
  • 8,151
  • 3
  • 55
  • 69
  • I don't have a good solution, what I did now was the following: Add a dummy element to the data structure, and in the `onChange` code just execute some code when this dummy element is changed. Finally, trigger the updates manually. This way still thousands of onChange events are triggered, but they are nearly nops, and only when I trigger manually an update by changing the dummy element the real update happens. Not really optimal, but at least a solution. Of course one needs to take this dummy element into account in other areas of the GUI code :-( – Norbert Preining Oct 03 '17 at 06:08