6

I have an Observable<List<T>> that I want to display with a TableView<T>.

It seems as though there should be a library function in JavaFx to convert an RxJava Observable<List<T>> into a JavaFx ObservableList<T>, but if there is, I can't find it (though there's lots of support in RxJavaFx for going the other way).

Do I need to write my own ObservableListBase<T> implementation and my own implementation of ListChangeListener.Change, or is there a better way?

Should I just replace the items wholesale?

TableView<T> table = ...
Observable<List<T>> observable = ...

observable
  .observeOn(JavaFxScheduler.platform())
  .subscribe(updatedList -> {
    ObservableList<T> items = table.getItems();
    items.setAll(updatedList);
  });
David Moles
  • 48,006
  • 27
  • 136
  • 235
  • Maybe [RxJavaFX](https://github.com/ReactiveX/RxJavaFX) can help you. – DVarga Dec 20 '17 at 13:51
  • @DVarga RxJavaFX is where I found “lots of library support going the other way”. :( – David Moles Dec 20 '17 at 16:40
  • Have you developed your own implementation? If so, maybe you could post it as an answer – David Rawson Mar 13 '18 at 08:45
  • 1
    @DavidRawson I went with the `.observeOn(JavaFxScheduler.platform())` / `setAll()` solution. It performs fine for a small table with no sorting, which is all I have to worry about right now. I don't know how well it would work in the general case. – David Moles Mar 13 '18 at 16:00

0 Answers0