1

I've build a Gui using the scene builder application. I've loaded it into my application but I want to add components to a VBox buried in the design. It seems that all i have access to use is the AnchorPanel that is returned from FXMLLoader.load.

Is there any way more elegant then drilling down the children tree's to get to the component i want?

Thanks.

merjr
  • 149
  • 1
  • 13

1 Answers1

3

If you need to add to the VBox from some random class:

  1. give an fx:id to the VBox, say "vbox"
  2. create a Controller for the view and associate it to the view in the FXML
  3. in the Controller, add a @FXML VBox vbox; (where vbox it the same as the fx:id)
  4. retrieve the controller from the FXMLLoader and access the VBox: controller.vbox;.

If you just need to add something to the VBox when your view is loaded, follow 1 to 3 above and add the relevant code in the initialize method of the Controller.

Community
  • 1
  • 1
assylias
  • 321,522
  • 82
  • 660
  • 783
  • 1
    Your link showed me where i went wrong. I was using the static load(URL) instead of the FXMLLoader load(Stream). Thanks! – merjr Sep 17 '13 at 18:24