What is the best way to manage multithreading in JavaFX 8?

前端 未结 2 962
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-09 15:33

I\'m trying to find an efficient way to influence the shape and the content of the JavaFX GUI elements, such as simple Pane, with use of multithreading. Let\'s say

2条回答
  •  星月不相逢
    2021-02-09 16:22

    You can access the scene only from the JavaFX application thread. You need to wrap your code that accesses the scene graph in Platform.runLater():

    Platform.runLater(() -> {
        Circle circle = new Circle(50, 50, 10, Color.RED);
        pane.getChildren().clear();
        pane.getChildren().add(circle);
    });
    

提交回复
热议问题