title: Display a ProgressIndicator during an async loading of ListView items
body: <p>I am trying to display a  <code>ProgressIndicator</code> while performing an async background <code>ListView</code> item loading. The behaviour that I desire is:</p>
  
  <ol>
  <li>Before start loading the <code>ListView</code> items, display a <code>ProgressIndicator</code> with a <a href="http://docs.oracle.com/javafx/2/api/javafx/scene/control/ProgressIndicator.html#INDETERMINATE_PROGRESS" rel="nofollow">indeterminate</a> progress;</li>
  <li>Asynchronously start loading the <code>ListView</code> items;</li>
  <li>After the <code>ListView</code> items loading was finished, hide the <code>ProgressIndicator</code>.</li>
  </ol>
  
  <p>Here is a <a href="http://sscce.org/" rel="nofollow">ssce</a> of my unsuccessful attempt:</p>
  
  <pre><code>public class AsyncLoadingExample extends Application {
      public static void main(String[] args) {
          launch(args);
      }
  
      @Override
      public void start(Stage primaryStage) {
          final ListView&lt;String&gt; listView = new ListView&lt;String&gt;();
          final ObservableList&lt;String&gt; listItems = FXCollections.observableArrayList();
          final ProgressIndicator loadingIndicator = new ProgressIndicator();
          final Button button = new Button("Click me to start loading");
  
          primaryStage.setTitle("Async Loading Example");        
  
          listView.setPrefSize(200, 250);
          listView.setItems(listItems);
  
          loadingIndicator.setVisible(false);
  
          button.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
              @Override
              public void handle(ActionEvent event) {
                  // I have hoped it whould start displaying the loading indicator (actually, at the end of this
                  // method execution (EventHandler.handle(ActionEvent))
                  loadingIndicator.setVisible(true); 
  
                  // asynchronously loads the list view items
                  Platform.runLater(new Runnable() {
                      @Override
                      public void run() {
                          try {
                              Thread.sleep(2000l); // just emulates some loading time
  
                              // populates the list view with dummy items
                              while (listItems.size() &lt; 10) listItems.add("Item " + listItems.size());
                          } catch (InterruptedException e) {
                              e.printStackTrace();
                          } finally { 
                              loadingIndicator.setVisible(false);  // stop displaying the loading indicator
                          }                   
                      }
                  });
              }
          });
  
          VBox root = VBoxBuilder.create()
              .children(
                  StackPaneBuilder.create().children(listView, loadingIndicator).build(), 
                  button                  
              )
              .build();
  
          primaryStage.setScene(new Scene(root, 200, 250));
          primaryStage.show();
      }
  }
  </code></pre>
  
  <p>In this example, the <code>ListView</code> items are loaded asynchronously. However, the  <code>ProgressIndicator</code> do not show up. Still in this example, if I omit all the <code>Platform.runLater(...)</code> code, the <code>ProgressIndicator</code> shows up, but, of course, the <code>ListView</code> items are not loaded.</p>
  
  <p>Thus, how can I achieve the desired behaviour?</p>