title: JavaFX: How can I horizontally center an ImageView inside a ScrollPane?
body: <pre><code>viewScroll.setContent(new ImageView(bigimg));
  double w = viewScroll.getContent().getBoundsInLocal().getWidth();
  double vw = viewScroll.getViewportBounds().getWidth();
  
  viewScroll.getContent().setTranslateX((vw/2)-(w/2));
  
  viewScroll.toFront();
  </code></pre>
  
  <p>I set an ImageView with some Image inside the ScrollPane but the ImageView always goes to the far left corner. Here I'm trying to manually offset the difference, but it doesn't work well. The ImageView goes too far to the right plus it only updates once because it's inside the eventhandler for a button. </p>