title: How to resize an image when resizing the window in JavaFX
body: <p>I want an image to be resized automatically when the user drags the main window. Is that possible?</p>
  
  <p>I have the following code that sets a window of a certain size. It also loads the image from an external URL.</p>
  
  <pre><code>@Override
  public void start(Stage primaryStage) {
  
      MenuBar menuBar=new MenuBar();
      Menu menuGame = new Menu("Game");
      MenuItem newGame = new MenuItem("New Game                F1");
      MenuItem exit = new MenuItem("Exit                            F2");
      exit.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
  
          @Override
          public void handle(ActionEvent event) {
              primaryStage.close();
          }
  
      });
      menuGame.getItems().addAll(newGame,new SeparatorMenuItem(),exit);
      menuBar.getMenus().addAll(menuGame);
  
      Image image = new Image("http://docs.oracle.com/javafx/"
      + "javafx/images/javafx-documentation.png");
      ImageView imageView = new ImageView();
      imageView.setImage(image);
  
  
      VBox vbox=new VBox();
      StackPane root=new StackPane();
      root.getChildren().addAll(imageView);
  
      vbox.getChildren().addAll(menuBar,root);
  
      Scene scene= new Scene(vbox,400,400);
      primaryStage.setScene(scene);
  
      primaryStage.setMaxHeight(800);
      primaryStage.setMinHeight(400);
      primaryStage.setMaxWidth(1000);
      primaryStage.setMinWidth(800);
  
      primaryStage.setTitle("Minesweeper");
      primaryStage.show();
  
  }
  </code></pre>