title: Set stackPane size in JavaFX
body: <p>I want a stack pane to simulate a FullHD display, that is 1920x1080. </p>
  
  <p>For that I am using 640x360 which follows the same proportion and then I scale the image nodes inside the stackPane (which is called "screen") using: </p>
  
  <pre><code>image.getWidth()/(fullWidth/screen.getWidth())), 
  
  image.getHeight()/(fullHeight/screen.getHeight()))
  </code></pre>
  
  <p>This is working great only problem is I can't set the size for the "screen" therefore it keeps big black bars on the bottom and on the top of it. </p>
  
  <p>As you can see in the image below the "screen" has a white border around it for making the black bars easier to notice.</p>
  
  <p><a href="https://i.stack.imgur.com/nFsP2.png" rel="nofollow noreferrer">screen snapshot</a></p>
  
  <p>Here is the code that creates the stack pane and handles it:</p>
  
  <p>DisplayPane constructor method</p>
  
  <pre><code>public DisplayPane(TemporalViewPane temporalViewPane, SteveMenuBar steveMenuBar, SpatialTemporalView spatialTemporalView){
  
          setId("display-pane");
  
          screen = new StackPane();
          screen.setId("screen-pane");
  
  
          controlButtonPane = new ControlButtonPane(screen, temporalViewPane, steveMenuBar, spatialTemporalView);
  
  
          setCenter(screen);
          setBottom(controlButtonPane);
  
      }
  </code></pre>
  
  <p>ControlButtonPane constructor class method:</p>
  
  <pre><code>public ControlButtonPane(StackPane screen, TemporalViewPane temporalViewPane,SteveMenuBar steveMenuBar, SpatialTemporalView spatialTemporalView){
  
      fullHDLabel = new Label("FullHD");
      fullHDLabel.setPadding(new Insets(5,5,5,5));   
      screen.getChildren().add(fullHDLabel);
  
      setId("control-button-pane");
      this.steveMenuBar = steveMenuBar;
      this.screen = screen;
      this.screen.setAlignment(Pos.TOP_LEFT);
      this.temporalViewPane = temporalViewPane;
      this.spatialTemporalView = spatialTemporalView;
      this.webView = new WebView();
  
      createButtons();
      setLeft(fullButtonPane);
      setLeft(fullHDLabel);
      setCenter(centerButtonPane);
      setRight(refreshButtonPane);
  
      createListeners();
      createButtonActions();
  
  
  }
  </code></pre>
  
  <p>CreateButtons method:</p>
  
  <pre><code>public void createButtons(){
  
  
      run = new Button();
      run.setDisable(true);
      run.setId("run-button");
      run.setTooltip(new Tooltip(Language.translate("run")));
  
      play = new Button();
      play.setDisable(true);
      play.setId("play-button");
      play.setTooltip(new Tooltip(Language.translate("play")));
  
      pause = new Button();
      pause.setDisable(true);
      pause.setId("pause-button");
      pause.setTooltip(new Tooltip(Language.translate("pause")));
  
      stop = new Button();
      stop.setDisable(true);
      stop.setId("stop-button");
      stop.setTooltip(new Tooltip(Language.translate("stop")));       
  
      centerButtonPane = new HBox();
      centerButtonPane.setId("center-button-pane");
      centerButtonPane.getChildren().add(run);
      centerButtonPane.getChildren().add(play);
      centerButtonPane.getChildren().add(pause);
      centerButtonPane.getChildren().add(stop);
  
  
  }
  </code></pre>
  
  <p>CreateListeners method:</p>
  
  <pre><code>private void createListeners(){
  
  
      screen.widthProperty().addListener((obs, oldVal, newVal) -&gt; {
          if(newVal != oldVal){
              screen.minHeightProperty().bind(screen.widthProperty().multiply(0.565));
              screen.maxHeightProperty().bind(screen.widthProperty().multiply(0.565));
              System.out.println("NEW WIDTH OF SCREEN IS: "+newVal);
          }
  
      });
  
      screen.heightProperty().addListener((obs, oldVal, newVal) -&gt; {
          if(newVal != oldVal){
              screen.minHeightProperty().bind(screen.widthProperty().multiply(0.565));
              screen.maxHeightProperty().bind(screen.widthProperty().multiply(0.565));
              System.out.println("NEW HEIGHT OF SCREEN IS: "+newVal);
          }
  
      });
  </code></pre>
  
  <p>And below is what I want to achieve. Currently, I have to run the application and then drag the side of the stack pane for resizing it as it should be.</p>
  
  <p><a href="https://i.stack.imgur.com/30VHH.png" rel="nofollow noreferrer">how it should be snapshot</a></p>
  
  <p>I've tried all set min/max/pref height/width and still haven't manage to achieve my goal. I don't know what else to do.</p>
  
  <p>Any help would be great.</p>