Is it okay to modify the `ObservableList` used by ...
# tornadofx
s
Is it okay to modify the
ObservableList
used by a tableview from another thread?
d
It is not okay. You'll have to post the modification to the main thread.
g
Definitely not. You can runLater it. This does lead to one of those geekery holes, though, where everyone on the team has to remember a rule. An approach I've used: Wrap the ObservableList, keeping it hidden from all clients that aren't the direct JavaFx observers of it. Now implement the parts of its API your code really needs on that wrapper. Very often, it's just two-three methods. Implement them using a thread-indifferent technique, like runLater. That way the team doesn't add to the large number of rules it has to remember to use the code.
A cautionary tale: I decided early on I wanted live updating of a ListView, and went to extraordinary pains to get the worker threads pumping it safely, including lots and lots of annoying code to generalize everything. My actual customer couldn't have cared less, because the workers were so fast they never actually cared about interim results. ­čÖé