title: Is there a way to get controller from a node JavaFX
body: <p>I'm trying to populate a <code>VBox</code> using custom FXML layout.</p>
  
  <p>Anyone know how to get access to controller so I can pass data?</p>
  
  <pre><code>public class Employee implements Initializable {
  
      @FXML
      private VBox pnItems = null;
  
  
      @Override
      public void initialize(URL location, ResourceBundle resources) {
          Node[] nodes = new Node[10];
          for (int i = 0; i &lt; nodes.length; i++) {
              try {
  
                  final int j = i;
                  nodes[i] = FXMLLoader.load(getClass().getResource("Item.fxml"));
  
                  //give the items some effect
  
                  nodes[i].setOnMouseEntered(event -&gt; {
                      nodes[j].setStyle("-fx-background-color : #0A0E3F");
                  });
                  nodes[i].setOnMouseExited(event -&gt; {
                      nodes[j].setStyle("-fx-background-color : #02030A");
                  });
  
  
  
  
                  pnItems.getChildren().add(nodes[i]);
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/y8omT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y8omT.png" alt=""></a></p>