title: JavaFX: canvas does not display anything
body: <p>I just began to study JavaFx. Sorry for the basic question, but I got stuck here for a couple of days. </p>
  
  <p>I built a FXML based project, and want to display something in a Canvas. Canvas is embedded in a stackpane, and the stackpane is embedded in a FXML window. There is a button in the window, when I click it, the Canvas should display some shapes. </p>
  
  <p>Now the problem is, the Canvas does not display anything. <code>ActionButtonStart</code> is the button action method. Thanks a lot!!</p>
  
  <pre><code>public class MainController implements Initializable{
      @FXML
      private StackPane windowHolder; 
      @FXML
      private Canvas mainCanvas;
  
      @Override
      public void initialize(URL location, ResourceBundle resources) {
          mainCanvas = new Canvas();
          windowHolder = new StackPane(); 
      }
  
      public void ActionButtonStart(ActionEvent event){
          //WindowNavigator.loadWindow(WindowNavigator.WINDOW_1_Welcome);
          final GraphicsContext gc = mainCanvas.getGraphicsContext2D();
          gc.clearRect(0, 0, mainCanvas.getWidth(), mainCanvas.getHeight());
  
          gc.setFill(Color.BLACK);
          gc.setFont(Font.getDefault());
          gc.fillText("hello   world!", 15, 50);
  
          gc.setLineWidth(5);
          gc.setStroke(Color.PURPLE);
  
          gc.strokeOval(10, 60, 30, 30);
          gc.strokeOval(60, 60, 30, 30);
          gc.strokeRect(30, 100, 40, 40);
  
                  windowHolder.getChildren().add(mainCanvas);
      }
  
      public void setWindow(Node node) {
          windowHolder.getChildren().setAll(node);
      }   
  
  }
  </code></pre>