title: Inserting a row into a Gridpane
body: <h1>I'm trying to insert a row into a grid pane.</h1>
  
  <h1>How can I achieve this?</h1>
  
  <p>Further reading/information/effots:</p>
  
  <p>I've been able to append the row with this:</p>
  
  <pre><code>    add.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
  
          @Override
          public void handle(ActionEvent event) {
              Peak thisPeak = new Peak();
              MenuPeak dispPeak = new MenuPeak(thisPeak);
              int row = 1+thisPeak.peakCount();
              //psMenu.addRow(1+row);
              psMenu.add(dispPeak.name,1,row,1,1);
              psMenu.add(dispPeak.retTime,2,row,1,1);
              psMenu.add(dispPeak.tol,3,row,1,1);
          }
  
      });
  </code></pre>
  
  <p>Which takes my original menu layout from</p>
  
  <p><a href="https://i.stack.imgur.com/YvOKk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YvOKk.png" alt="Start"></a></p>
  
  <p>to</p>
  
  <p><a href="https://i.stack.imgur.com/QRKHc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QRKHc.png" alt="enter image description here"></a></p>
  
  <p>I tried googling, some people suggested using an addRow.  I've tried a few variants (currently one is commented out in the snippet I provided.  </p>
  
  <p>This ends up just overwriting my buttons as seen:</p>
  
  <p><a href="https://i.stack.imgur.com/k0nUI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k0nUI.png" alt="enter image description here"></a></p>
  
  <p>I am ultimately wanting it to insert the row between the buttons as such (hard-coded the peak line):</p>
  
  <p><a href="https://i.stack.imgur.com/q4e3x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q4e3x.png" alt="enter image description here"></a></p>
  
  <p>Perhaps there is a better solution, but I found some success by re-adding the element buttons again, but this is producing some runtime errors yet is working?  </p>
  
  <pre><code>    add.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
  
          @Override
          public void handle(ActionEvent event) {
              Peak thisPeak = new Peak();
              MenuPeak dispPeak = new MenuPeak(thisPeak);
              int row = thisPeak.peakCount();
              psMenu.addRow(1+row);
              psMenu.add(dispPeak.name,1,row,1,1);
              psMenu.add(dispPeak.retTime,2,row,1,1);
              psMenu.add(dispPeak.tol,3,row,1,1);
              row++;
              psMenu.add(save,1,row,1,1);
              psMenu.add(cancel,2,row,1,1);
              psMenu.add(okay,3,row,1,1);
          }
  
      }); 
  </code></pre>
  
  <p>Which did make this </p>
  
  <p><a href="https://i.stack.imgur.com/FxQ5i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FxQ5i.png" alt="enter image description here"></a></p>
  
  <p>But again, the run time error complained about adding duplicate children.</p>
  
  <blockquote>
    <p>Exception in thread "JavaFX Application Thread"
    java.lang.IllegalArgumentExcepti on: Children: duplicate children
    added: parent = Grid hgap=10.0, vgap=10.0, alig nment=TOP_CENTER
            at javafx.scene.Parent$2.onProposedChange(Parent.java:454)
            at com.sun.javafx.collections.VetoableListDecorator.add(VetoableListDeco
    rator.java:206)</p>
  </blockquote>
  
  <p>EDIT:  The answer is correct and the exact implementation of my correction is:</p>
  
  <pre><code>    add.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
  
          @Override
          public void handle(ActionEvent event) {
              Peak thisPeak = new Peak();
              MenuPeak dispPeak = new MenuPeak(thisPeak);
              int row = 1+thisPeak.peakCount();
  
              psMenu.setRowIndex(save,row);
              psMenu.setRowIndex(cancel,row);
              psMenu.setRowIndex(okay,row);
  
              psMenu.addRow(row-1, dispPeak.name, dispPeak.retTime, dispPeak.tol);
  
          }
  
      });
  </code></pre>