Q:

Adding sub-menu dynamically to FXML via JavaFX

I have made a GUI interface via Scene Builder. I want to add child node to my Menu dynamically. 
The FXML code sample: 
<MenuBar VBox.vgrow="NEVER">
            <menus>
                <Menu mnemonicParsing="false" text="File">
                    <items>
                        <MenuItem mnemonicParsing="false" onAction="#handleCreateNew" text="New" />
                        <MenuItem mnemonicParsing="false" onAction="#handleOpen" text="Open…" />
                        <Menu fx:id="openRecentTab" mnemonicParsing="false" onAction="#handleOpenRecentAction" text="Open Recent">
                            <items>
                                <MenuItem mnemonicParsing="false" text="" />
                                <MenuItem mnemonicParsing="false" text="" />
                                <MenuItem mnemonicParsing="false" text="" />
                            </items>
                        </Menu>
                        <SeparatorMenuItem mnemonicParsing="false" />
                        <MenuItem mnemonicParsing="false" onAction="#handleFileClose" text="Close" />
                        <MenuItem mnemonicParsing="false" onAction="#handleSave" text="Save" />
                        <MenuItem mnemonicParsing="false" onAction="#handleSaveAs" text="Save As…" />
                        <SeparatorMenuItem mnemonicParsing="false" />
                        <MenuItem mnemonicParsing="false" onAction="#handleQuit" text="Quit" />
                    </items>
                </Menu>
            </menus>
        </MenuBar>

I want to change or add new <MenuItem> to my <Menu fx:id="openRecentTab" mnemonicParsing="false" onAction="#handleOpenRecentAction" text="Open Recent">
Thanks

A:

I'm assuming that you have linked a controller with the FXML file, as you have defined onAction triggers in it. However in case you haven't.
1- Create a new java file that will act as the controller of the FXML and place it in the same package as the FXML file. Suppose you named that class MyController.
2- Link that Controller to your FXML. You can do that in scene builder this way:

3- In your Controller class add the following
public class MyController {

    @FXML private Menu openRecentTab;

    @FXML public void addMenuItem() {
        MenuItem menuItem1 = new MenuItem("Menu Item 1");
        MenuItem menuItem2 = new MenuItem("Menu Item 2");    
        MenuItem menuItem3 = new MenuItem("Menu Item 3");

        // Add multiple items at once
        openRecentTab.getItems().addAll(menuItem1, menuItem2);
        // Add one item
        openRecentTab.getItems().add(menuItem3);
    }
}

4- You can set the addMenuItem method to be called when for example a certain button is clicked. To do that set the onAction attribute of the button you want to trigger adding a new Item in your fxml to #<methodName> or in this instance #addMenuItem
Note: If you don't want to add your menu items through a trigger, and instead you want to add them dynamically before the stage(window) of your program is shown. You can use the initialize method to do this. To do this make your MyController class implements Initializable in this way: 
public class MyController implements Initializable{

    @FXML private Menu openRecentTab;

    // This method is called before the stage is shown
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        MenuItem menuItem1 = new MenuItem("Menu Item 1");
        MenuItem menuItem2 = new MenuItem("Menu Item 2");
        openRecentTab.getItems().addAll(menuItem1, menuItem2);
    }
}

