I'm trying to insert a row into a grid pane.
How can I achieve this?
Further reading/information/effots:
I've been able to append the row with this:
add.setOnAction(new EventHandler<ActionEvent>() {
@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);
}
});
Which takes my original menu layout from
to
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.
This ends up just overwriting my buttons as seen:
I am ultimately wanting it to insert the row between the buttons as such (hard-coded the peak line):
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?
add.setOnAction(new EventHandler<ActionEvent>() {
@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);
}
});
Which did make this
But again, the run time error complained about adding duplicate children.
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)
EDIT: The answer is correct and the exact implementation of my correction is:
add.setOnAction(new EventHandler<ActionEvent>() {
@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);
}
});