title: Adding dynamic entries to Menu in JavaFX
body: <p>I'm trying to dynamically add entries to a JavaFX menu. I have a program that can draw graphs, each time a new graph is drawn, I add an entry to the an <code>ObservableList</code> with all graphs.<br>
  My <code>controller</code> observes the list and on each change, it should modify the <code>Menu</code> in the <code>JavaFX view</code>. However I'm running in a problem when doing so.<br> On the first add, it shows as expected <code>the first entry</code>.<br> On the second add, the list contains <code>the first entry + the first entry + the last entry</code>.<br> On the third add it shows the <code>first entry + the first entry + the second entry + the first entry + the second entry + the last entry</code>. I guess you can guess the pattern from this point forward.<br>
  This code snippet is taken from my controller:</p>
  
  <pre><code>graphHandler.getGraphs().addListener(new ListChangeListener&lt;Graph&gt;() {
  //GraphHandler.class is my model, that holds the list with all graphs
      @Override
      public void onChanged(Change&lt;? extends Graph&gt; c) {
          Menu history = graphView.getHistoryMenu();
          history.getItems().removeAll();
          //on change get the Menu from the model and empty it
          String changes = (String) c.toString();
          System.out.println(changes);
          //Output will be added below snippet
          graphHandler.getGraphs().forEach((Graph graph) -&gt; {
              String root = graph.getRootNode().toString();
              MenuItem item = new MenuItem(root);
              //Get the graph's root node name and add a MenuItem with it's name
              item.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
              //On choosing a MenuItem load the according graph; works fine
                  @Override
                  public void handle(ActionEvent event) {
                      graphHandler.getGraphByRootNode(root);
                  }
              });
              history.getItems().addAll(item);
              //Add all MenuItems to the Menu
          });
      }
  });
  </code></pre>
  
  <p>My approach was to empty the <code>Menu</code> on every change and refill it, but it doesn't seem to work. Does anybody have an Idea what I'm missing?<br></p>
  
  <pre><code>{ [com.example.d3project.model.Graph@7eb5106] added at 0 }
  { [com.example.d3project.model.Graph@f510ff2] added at 1 }
  { [com.example.d3project.model.Graph@69239a8d] added at 2 }
  </code></pre>
  
  <p>The output shows what I'm expecting to see. Also the <code>size()</code> of the <code>ObservableList</code> is as I'm expecting it.</p>