Question: I looked online but I couldn't find it. How can I get the name of the clicked menu item when somebody clicks it.I want to change the scene according to the clicked menu item but I don't want to create 8 different methods. If I can get the name of the clicked menu item I can create 1 method that takes that name as a parameter and launches the FXML Loader and changes the scene[![enter image description here](https://i.stack.imgur.com/5v0Ee.jpg)](https://i.stack.imgur.com/5v0Ee.jpg)

Answer: 
Register an inline listener to the MenuItem(s) onAction event in the initialization method.

```
for (MenuItem item : menu.items()) {
item.setOnAction(new EventHandler<ActionEvent>() {
    @Override
    public void handle(ActionEvent event) {
        processCategory(item.getText()); // this would do your thing you want to do.
        event.consume();
    });

}

```
As is mentioned here: <https://www.programcreek.com/java-api-examples/?class=javafx.scene.input.MouseEvent&method=getSource>

You can do it like:

```
private void handleLabel(MouseEvent event) { 
    Node label = (Node) event.getSource();
    System.out.println("Mouse click on label: " + label.getId());
}

```