title: How to show a dynamically changing text inside CombBox ListView
body: <p>I want to show a dynamically changing loading text inside a <code>ComboBox</code> list while the contents of the list are being loaded. Showing some text while I'm getting the content is no issue. The issue is getting that text to change dynamically. This code will display a dynamically changing message as a <code>Label</code>:</p>
  
  <pre><code>import javafx.animation.KeyFrame;
  import javafx.animation.Timeline;
  import javafx.application.Application;
  import javafx.event.Event;
  import javafx.event.EventHandler;
  import javafx.geometry.Pos;
  import javafx.scene.Scene;
  import javafx.scene.control.Label;
  import javafx.scene.layout.VBox;
  import javafx.stage.Stage;
  import javafx.util.Duration;
  
  public class SSCCE extends Application {
  
      @Override
      public void start(Stage stage) {
  
          VBox root = new VBox();
  
          final Label message = new Label("Loading");
  
          final Timeline timeline = new Timeline(new KeyFrame(
                  Duration.ZERO, new EventHandler() {
                      @Override
                      public void handle(Event event) {
                          String messageText = message.getText();
                          message.setText(("Loading . . ."
                                  .equals(messageText)) ? "Loading ."
                                  : messageText + " .");
                      }
                  }), new KeyFrame(Duration.millis(500)));
          timeline.setCycleCount(Timeline.INDEFINITE);
  
          root.getChildren().add(message);
  
          timeline.play();
  
          Scene scene = new Scene(root);
          stage.setScene(scene);
          stage.show();
  
      }
  
      public static void main(String[] args) {
          launch();
      }
  }
  </code></pre>
  
  <p>But the problem is that since putting <code>Node</code> objects into the item list is <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ComboBox.html" rel="nofollow">strongly not recommended</a>(And it looks really weird). I need to put them in something else.</p>
  
  <p>I thought I solved this by using a <code>SimpleStringProperty</code> since it implements <code>Observable</code>:</p>
  
  <pre><code>import javafx.animation.KeyFrame;
  import javafx.animation.Timeline;
  import javafx.application.Application;
  import javafx.beans.property.SimpleStringProperty;
  import javafx.event.Event;
  import javafx.event.EventHandler;
  import javafx.scene.Scene;
  import javafx.scene.control.ComboBox;
  import javafx.scene.layout.VBox;
  import javafx.stage.Stage;
  import javafx.util.Duration;
  
  public class SSCCE2 extends Application {
  
      @Override
      public void start(Stage stage) {
  
          VBox root = new VBox();
  
          final SimpleStringProperty message = new SimpleStringProperty("Loading");
  
          final Timeline timeline = new Timeline(new KeyFrame(
                  Duration.ZERO, new EventHandler() {
                      @Override
                      public void handle(Event event) {
                          String messageText = message.getValue();
                          message.setValue(("Loading . . ."
                                  .equals(messageText)) ? "Loading ."
                                  : messageText + " .");
                      }
                  }), new KeyFrame(Duration.millis(500)));
          timeline.setCycleCount(Timeline.INDEFINITE);
  
          ComboBox&lt;SimpleStringProperty&gt; comboBox = new ComboBox&lt;SimpleStringProperty&gt;();
          comboBox.getItems().add(message);
  
          timeline.play();
  
          root.getChildren().add(comboBox);
  
          Scene scene = new Scene(root);
          stage.setScene(scene);
          stage.show();
  
      }
  
      public static void main(String[] args) {
          launch();
      }
  }
  </code></pre>
  
  <p>But it doesn't work. It just displays "Loading ." all the time. And yes. The <code>ComboBox</code> currently displays the <code>toString()</code> method of <code>SimpleStringProperty</code>, but that can easily be fixed by setting the cell factory or converter of the <code>ComboBox</code>. I didn't add that part here since I wanted to keep the example as small as possible. Also that kind of method would display the getValue() of SimpleStringProperty, which isn't <code>Observable</code>, and we're back to square one again.</p>
  
  <p>Anyhow. With this example nothing happens. This is weird to me since <code>SimpleStringProperty</code> implements <code>Observable</code>, which should mean that any change will be displayed.</p>