title: Get fx:id from label clicked to get its text from controller
body: <p>Using JavaFX and Scene Builder, I am trying to access the text inside a Label from the controller.</p>
  
  <p>I initialized a label as follows in the controller:</p>
  
  <pre><code>@FXML
  private Label label1;
  </code></pre>
  
  <p>The following code is in the fxml file:</p>
  
  <pre><code>&lt;Label fx:id="lable1" onMouseClicked="#handleLabel" text="Label 1" /&gt;
  </code></pre>
  
  <p>I have bound the label to this function in the controller using scene builder:</p>
  
  <pre><code>private void handleLabel(MouseEvent event) { 
  // get text from label n
  }
  </code></pre>
  
  <p>My idea was to call something like <code>label1.getText()</code>. But for that I need to get the fx:id of the label, and since I will many labels, I cannot hardcode all the id cases individually.</p>
  
  <p><a href="https://stackoverflow.com/questions/24302636/better-way-for-getting-id-of-the-clicked-object-in-javafx-controller">Better way for Getting id of the clicked Object in JavaFX controller</a>
  I have found this, but I do not think the this answer works for me because initializing the label and setting an id does not seem to cope with @FXML. 
  Also, it has not been answered whether it is possible to access the fx:id of a component.</p>
  
  <p>Any other way for how to access the Label object's methods like <code>getText()</code> are also welcome.</p>