Platform.runLater and Task in JavaFX

前端 未结 4 543
孤独总比滥情好
孤独总比滥情好 2020-11-22 08:54

I have been doing some research on this but I am still VERY confused to say the least.

Can anyone give me a concrete example of when to use Task and whe

4条回答
  •  无人及你
    2020-11-22 09:10

    One reason to use an explicite Platform.runLater() could be that you bound a property in the ui to a service (result) property. So if you update the bound service property, you have to do this via runLater():

    In UI thread also known as the JavaFX Application thread:

    ...    
    listView.itemsProperty().bind(myListService.resultProperty());
    ...
    

    in Service implementation (background worker):

    ...
    Platform.runLater(() -> result.add("Element " + finalI));
    ...
    

提交回复
热议问题