title: JavaFX2 FXML how to add elements (e.g. Buttons) dynamically
body: <p>So, what I want to do is, creating a custom element by using fxml and then add a couple of instances of that element into a container, like GridPane. The "new" operators does not work for me, because I would like to use the @fxml annotator to get access to the element. Cloning would be nice, but it does not work. The FXMLLoader is very slow, when using in a for() contruct to add many elements.
  It would be perfect, if I could write a reference into fxml parentnode, which could be called from the controller. </p>
  
  <p>Sorry... here in pseudo...</p>
  
  <pre><code>public class Controller implements Initializable {
  
      @FXML
      private VBox stack;
  
      @FXML
      private Button button;
  
      @FXML
      private void Change(KeyEvent event) throws IOException {     
          for (int i=0; i&lt;10; i++){
              stack.getChildren().add(button);   
          }
      }
  
  }
  </code></pre>
  
  <p>It is no problem to add THE button to the VBox. But in a for-contruct (to add MORE THAN ONE Button) it fails. I could use the new operator in the for construct, but I want to know, if this is the only possiblity. I thought there must be another way e.g. to use the @FXML annotator to "get" the button and then duplicate it.</p>