title: JavaFX scroll to bottom of tableview when items are added to it
body: <p>Odd one here, I can't quite work out how to get around this one. I have a tableview that gets populated when a listener to an observable list picks up there has been a change. So this is the code for that:</p>
  
  <pre><code>userController.getAuthImpl().listOfMessages.addListener(new ListChangeListener&lt;Message&gt;() {
      @Override
      public void onChanged(ListChangeListener.Change&lt;? extends Message&gt; c) {
          addMessageToTableView(tblvwBottomAdminNotifications, c.getList());
      }
  });
  
  
  public void addMessageToTableView(TableView&lt;Message&gt; tblvw, ObservableList&lt;? extends Message&gt; observableList){
      tblvw.getItems().clear();
      for(Message msg: observableList)
          tblvw.getItems().add(msg);
  }
  public ObservableList&lt;Message&gt; listOfMessages = FXCollections.observableArrayList(_listOfMessages);
  </code></pre>
  
  <p>This works fine and the table automatically updates once an item is added to the listOfMessages. The bit that I would like to do now, is to scroll the listview to the bottom when it is updated. I've attempted adding the following line to the addMessageToTableView method:</p>
  
  <pre><code>tblvw.scrollTo(tblvw.getItems().size()-1);
  </code></pre>
  
  <p>And have also attempted adding a change listener to the tableview itself like this:</p>
  
  <pre><code>tblvwBottomAdminNotifications.getItems().addListener(new ListChangeListener&lt;Message&gt;(){
  
      @Override
      public void onChanged(javafx.collections.ListChangeListener.Change&lt;? extends Message&gt; c) {
          tblvwBottomAdminNotifications.scrollTo(c.getList().size()-1);
  
      }
  
  });
  </code></pre>
  
  <p>But both error in the same way with the following message:</p>
  
  <blockquote>
    <p>Exception in thread "RMI TCP Connection(1)-192.168.56.1" java.lang.IllegalStateException: Not on FX application thread; currentThread = RMI TCP Connection(1)-192.168.56.1</p>
  </blockquote>
  
  <p>Which from my Google skills is JavaFX complaining I'm accessing the tableview from a separate thread. That I can understand, but how should I access it in such a way that when the tableview does get a new item added to it, it scrolls down to it?</p>
  
  <p>Let me know if you need more information.</p>