1 Reply Latest reply: Jan 15, 2013 9:17 AM by 984080 RSS

    Why are UI nodes manipulate operations blocked by the code after them?

    984474
       
      public void start(Stage stage) throws Exception {
           BorderPane root = new BorderPane();
           
           final Pane pane = new Pane();
           Button button = new Button("Click Me");
           button.setOnAction(new EventHandler<ActionEvent>() {               
                @Override
                public void handle(ActionEvent arg0) {
                     Rectangle rectangle = new Rectangle(300, 100);
                     rectangle.setFill(new Color(Math.random(), Math.random(), Math.random(), 1));
                     pane.getChildren().clear();
                     pane.getChildren().add(rectangle);
                          
                     try {
                          Thread.sleep(3000);
                          } catch (InterruptedException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                     }               
                       }  
           });
           root.setCenter(pane);
           root.setBottom(button);
           Scene scene = new Scene(root, 500, 400);
           stage.setScene(scene);
           stage.show();          
      }
       
      The rectangle will be added to the pane after the thread wake up. I am new to JavaFX, who can help me? Thanks.

      Edited by: 981471 on Jan 12, 2013 5:29 AM

      Edited by: 981471 on Jan 12, 2013 5:30 AM

      Edited by: 981471 on Jan 12, 2013 5:30 AM

      Edited by: 981471 on Jan 12, 2013 5:31 AM