title: JavaFX - Resize Canvas when screen is resized
body: <p>I'm working on the GUI of my level editor that I built in JavaFX, and I want to be able to resize the canvas object to the new split pane dimensions. It seems that everything I've tried has failed. This includes passing the pane object in and using its width directly, using window size listeners and binding the width and height property to that of the split pane. Any ideas? This is what it looks like before a resize:</p>
  <p><img src="https://i.stack.imgur.com/ld6sr.png" alt="enter image description here" /></p>
  <p>And after a resize:</p>
  <p><img src="https://i.stack.imgur.com/tVtX7.png" alt="enter image description here" /></p>
  <p>Does anybody have any ideas? The code for the class is pretty extensive, but the code for the resizing will be included here:</p>
  <pre><code>public Canvas canvas;
  public String tabTitle;
  public VBox layout;
  public GraphicsContext g;
  public Core core;
  
  public CanvasTab(Core core, String tabTitle){
      this.core = core;
      this.canvas = new Canvas(core.scene.getWidth() - 70, core.scene.getHeight() - 70);
      layout = VBoxBuilder.create().spacing(0).padding(new Insets(10, 10, 10, 10)).children(canvas).build();
      
      this.g = canvas.getGraphicsContext2D();
  
      g.setFill(Color.BLACK);
      g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
      
      HBox.setHgrow(layout, Priority.ALWAYS);
      
      this.setContent(layout);
      this.setText(tabTitle);
      
      canvas.widthProperty().bind(layout.widthProperty().subtract(20));
      canvas.heightProperty().bind(layout.heightProperty().subtract(20));
  }
  
  public CanvasTab(Canvas canvas){
      this.canvas = canvas;
  }
  </code></pre>