简体   繁体   中英

JavaFX Scene Builder - How can I access the components

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM