title: How to set an image to the size of a button in JavaFX
body: <p>I'm using JavaFX for school and I need to display a picture on a button when I click on it. My problem is that the image is bigger than the button and then everything is horrible. I have seen multiples post on how to fit a image to a button and I came with that code </p>
  
  <pre><code>Image imageOk = new Image(getClass().getResourceAsStream("/TP2/ressources/flag.png"));
  ImageView img = new ImageView(imageOk);
  img.setFitWidth(100);
  img.setFitHeight(100);
  btn.setGraphic(img);
  </code></pre>
  
  <p>When I create the button I use <code>setPrefSize(50, 50);
  </code></p>