title: JavaFX 8, how to get center location of Scrollpane's Viewport
body: <p><a href="https://i.stack.imgur.com/MGoYb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MGoYb.png" alt="Viewport Center" /></a></p>
  <p><strong>The Problem</strong></p>
  <p>I'm trying to figure out a way to get at which point <em>in the content node</em> the scroll pane's viewport is centered on.</p>
  <p>To elaborate on the picture above, the big rectangle is the content (let's say a large image), and the small rectangle is the portion that is shown by the scroll pane. I'm trying to find x and y which would be coordinates from the top left of the content.</p>
  <p><strong>What I've Tried</strong></p>
  <p>My first thought was to use the <code>getViewportBounds()</code> method of the scroll pane and use its <code>minX</code> and <code>maxX</code> properties to determine the center x point:</p>
  <pre><code>Bounds b = scrollPane.getViewportBounds();
  double centerX = (b.getMinX() + b.getMaxX()) / 2;
  double centerY = (b.getMinY() + b.getMaxY()) / 2;
  </code></pre>
  <p>However, this doesn't work because these numbers are <em>negative</em> and don't seem to accurately describe the <strong>x</strong> and <strong>y</strong> I'm looking for anyways.</p>
  <p>My next thought was to use the scroll pane's <code>hValue</code> and <code>vValue</code> to get the top left corner of the viewport relative to the content:</p>
  <pre><code>Bounds b = scrollPane.getViewportBounds();
  double centerX = scrollPane.getHvalue() + b.getWidth() / 2;
  double centerY = scrollPane.getVvalue() + b.getHeight() / 2;
  </code></pre>
  <p>This didn't work either though as the <code>hValue</code> and <code>vValue</code> seem to be way too large (when scrolled in only a few pixels, I'm getting numbers like 1600).</p>
  <p><strong>My Questions</strong></p>
  <p>I seem to have a fundamental misunderstanding of how the viewport works with a scroll pane.</p>
  <p>What am I doing wrong here? Can someone explain where these numbers come from? How do I find <strong>x</strong> and <strong>y</strong> like in the picture above?</p>