Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the corresponding Node a controller is attached to

For a given controller is there anyway built-in way to access the node that controller is "attached" to without having to give it a FXML ID and specific annotation? I can't find anything relevant to this in the official documentation or searching online.

For example, how do I access the HBox from org.example.FooController

<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.example.FooController">
   <children>
      <Button mnemonicParsing="false" text="Button" />
   </children>
</HBox>

For now I've just been giving the node a FXML ID of "root" and then using the following in my controller, but it feels like I'm missing a trick...

@FXML
private Node root
like image 514
Adam Avatar asked Feb 02 '15 12:02

Adam


1 Answers

Consensus appears to be there is no magic way to do this if your controller is nested or not involved in the loading process.

I've been sticking to the convention of fx:id of "root", and matching @FXML

@FXML
private Node root
like image 150
Adam Avatar answered Sep 18 '22 00:09

Adam