title: How to find the indices of the visible rows in a TableView in JavaFX 9
body: <p>How do I get the indices of the visible rows in a TableView in JavaFX 9? In JavaFX 8, I can do the following:</p>
  
  <pre><code>  // --- The offending imports in Java 9
    // import com.sun.javafx.scene.control.skin.TableViewSkin;
    // import com.sun.javafx.scene.control.skin.VirtualFlow;
  
    /**
     * This is a total hack. We need it as scrollTo jumps the selected
     * row to the top of the table. Jarring if the row is already 
     * visible. As a workaround, we only scroll if the row isn't already
     * visible
     *
     * @return A 2 element ray with the start and end index of visible rows
     */
    public int[] getVisibleRows() {
        TableView&lt;?&gt; tableView = getTableView();
        TableViewSkin&lt;?&gt; skin = (TableViewSkin&lt;?&gt;) tableView.getSkin();
        if (skin == null) return new int[] {0, 0};
        VirtualFlow&lt;?&gt; flow = (VirtualFlow&lt;?&gt;) skin.getChildren().get(1);
        int idxFirst;
        int idxLast;
        if (flow != null &amp;&amp;
                flow.getFirstVisibleCellWithinViewPort() != null &amp;&amp;
                flow.getLastVisibleCellWithinViewPort() != null) {
            idxFirst = flow.getFirstVisibleCellWithinViewPort().getIndex();
            if (idxFirst &gt; tableView.getItems().size()) {
                idxFirst = tableView.getItems().size() - 1;
            }
            idxLast = flow.getLastVisibleCellWithinViewPort().getIndex();
            if (idxLast &gt; tableView.getItems().size()) {
                idxLast = tableView.getItems().size() - 1;
            }
        }
        else {
            idxFirst = 0;
            idxLast = 0;
        }
        return new int[]{idxFirst, idxLast};
    }
  </code></pre>
  
  <p>In Java 9, as part of the modularization, the JDK team is hiding the API's that weren't meant to be public (e.g. all packages that start with 'com.sun') If I try to compile this in Java 9, I get errors of:</p>
  
  <pre><code>  [...] cannot find symbol
    [ERROR]   symbol:   class TableViewSkin
    [ERROR]   location: package com.sun.javafx.scene.control.skin
  
    [...] cannot find symbol
    [ERROR]   symbol:   class VirtualFlow
    [ERROR]   location: package com.sun.javafx.scene.control.skin
  </code></pre>
  
  <p>Is there any official way to get the visible rows in a TableView? Any ideas on another, better workaround for this?</p>
  
  <p><strong>UPDATED: Solution based on @user4712734's solution</strong></p>
  
  <pre><code>TableViewExt&lt;?&gt; tableViewExt = new TableViewExt&lt;&gt;(tableView);
  
  public int[] getVisibleRows() {
      return new int[]{ tableViewExt.getFirstVisibleIndex(), 
                        tableViewExt.getLastVisibleIndex()};
  }
  </code></pre>
  
  <p><a href="https://gist.github.com/hohonuuli/29dba349e6cf7d55bdb9d17e97392720" rel="nofollow noreferrer">Code for TableViewExt</a></p>