title: Scaling an ImageView to a specific height in JavaFX
body: <p>I have an <code>Imageview</code> in my menu which shows a preview of a chosen map. </p>
  
  <p>But these maps can vary in size, in my menu I have enough horizontal space, but vertically I have limits. So, what I want is to scale the <code>ImageView</code> in a way that its height becomes 40 pixels (I also have a problem here) and it's width change accordingly in a way that it does not deform.</p>
  
  <p>Also I would appreciate it so much if there is a way to have the height automatically fit to the height of it's line.(its parent)
  Here is my code:</p>
  
  <pre><code>Label mapChooserLabel = new Label("This is the map you will play on, click to change");
  try {
      mapPreview = new ImageView(
          new Image(getClass().getResource("/files/images/maps/" + chosenMapName + ".gif").toURI().toURL().toString())
      );
      mapPreview.setFitHeight(40);
      mapPreview.setOnMouseClicked(event -&gt; System.out.println("towerChooserPopup should open now!"));
  } catch (MalformedURLException | URISyntaxException e) {
      e.printStackTrace();
  }
  HBox mapChooserWrapper = new HBox(mapChooserLabel, mapPreview);
  mapChooserWrapper.setId("lineWrapper");
  </code></pre>
  
  <p>And here is my css:</p>
  
  <pre><code>#lineWrapper{
      -fx-alignment: center;
      -fx-spacing: 2px;
  }
  </code></pre>