title: JavaFX FXML - Getting MenuItem using fx:id
body: <p>I am building the GUI of a Java application using Scene Builder. For each element, I have given it a <code>fx:id</code> so that I can refer to them later. I need to use <code>setOnAction()</code> on many of its elements such as:</p>
  
  <pre><code>((Button)mainPane.lookup("#submitButton")).setOnAction(e-&gt;{
      // ... code triggered when button is pressed ...
  });
  </code></pre>
  
  <p>This works for most elements except <code>MenuItem</code>s. When I try the following, Eclipse tells me "Cannot cast from <code>Node</code> to <code>MenuItem</code>" and it does not work.</p>
  
  <pre><code>// Does not work
  ((MenuItem)mainPane.lookup("#about")).setOnAction(e-&gt;{
      // ... take user to about page ...
  });
  </code></pre>
  
  <p>I see that <code>MenuItem</code> only extends <code>Object</code>, so it cannot be casted from a <code>Node</code>. How can I get back the <code>MenuItem</code> using its <code>fx:id</code>? </p>
  
  <p>Note: I know I could use the <code>On Action</code> of FXML, but I want to utilize Lambda functions and keep the event-handling code in the same style.</p>