title: Create new radio button options during runtime
body: <p>I am using JavaFX and would like that when a button is clicked, a new radio button is created and displayed within a flowpane. Is this possible? I tried to do this but nothing seems to appear.</p>
  
  <p><strong>Edit:</strong>
  The problem seems to be originating from the insertDemand() method in the Controller class. The radio buttons appear if I remove the first two lines of the method. I have no idea why it does this. But I need when the button is clicked a line to appear on the screen as well as the radio button to appear so removing these two lines is not a feasible solution.</p>
  
  <p>Here is the fxml:</p>
  
  <pre><code>&lt;GridPane alignment="center" hgap="10" prefHeight="800.0" prefWidth="1200.0" stylesheets="/sample/sample.css" vgap="10" xmlns="http://javafx.com/javafx/8.0.76-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller"&gt;
      &lt;children&gt;
          &lt;!--Insert--&gt;
          &lt;ScrollPane GridPane.columnIndex="0" GridPane.rowIndex="1" GridPane.rowSpan="4"&gt;
              &lt;content&gt;
                  &lt;FlowPane&gt;
                      &lt;Button fx:id="demandB" mnemonicParsing="false" onAction="#insertDemand"  text="Demand" /&gt;
                  &lt;/FlowPane&gt;
              &lt;/content&gt;
          &lt;/ScrollPane&gt;
          &lt;StackPane fx:id="workspaceSP" GridPane.columnIndex="1" GridPane.rowIndex="0" GridPane.rowSpan="2"&gt;
          &lt;/StackPane&gt;
          &lt;ScrollPane GridPane.columnIndex="1" GridPane.rowIndex="3"&gt;
              &lt;content&gt;
                  &lt;FlowPane fx:id="lineButtonsFP" prefHeight="100.0"&gt;
                      &lt;Label text="Select a Curve:" /&gt;
  
                  &lt;/FlowPane&gt;
              &lt;/content&gt;
          &lt;/ScrollPane&gt;
      &lt;/children&gt;
      &lt;columnConstraints&gt;
          &lt;ColumnConstraints maxWidth="600.0" minWidth="392.0" prefWidth="400.0" /&gt;
      &lt;/columnConstraints&gt;
      &lt;rowConstraints&gt;
          &lt;RowConstraints maxHeight="200.0" minHeight="22.0" prefHeight="39.0" /&gt;
          &lt;RowConstraints /&gt;
      &lt;/rowConstraints&gt;
  &lt;/GridPane&gt;
  </code></pre>
  
  <p>Here is the Controller class:</p>
  
  <pre><code>public class Controller {
  
      static Parent graphMaker;
      @FXML
      StackPane workspaceSP;
      @FXML
      FlowPane lineButtonsFP;
      static LinkedList&lt;Demand&gt; curvesLL;
      ToggleGroup group = new ToggleGroup();
      public void insertDemand() {
          Demand demand = new Demand(workspaceSP,200,200,400,400);
          curvesLL.add(demand);
          RadioButton radioButton = new RadioButton("Demand");
          radioButton.setToggleGroup(group);
          radioButton.setSelected(true);
          lineButtonsFP.getChildren().add(radioButton);
      }
  }
  </code></pre>
  
  <p>Demand is a class I've made. When created, a line is displayed:</p>
  
  <pre><code>public class Demand {
  
          public Demand(Pane pane, double startX, double startY, double endX, double endY){
              pane.getChildren().add(makeLine(startX, startY, endX, endY));
          }
  
          private Line makeLine(double startX, double startY, double endX, double endY) {
              Line line = new Line(startX, startY, endX, endY);
              return line;
          }
      }
  
  }
  </code></pre>
  
  <p>Thank you for your help :)</p>
  
  <p><strong>Edit 2:</strong> I found how to make it work. No idea why this fixes the problem but if you move the first two lines of the insertDemand() method to the bottom so that the radio button is made first and then the Deman object is created, then it works.</p>