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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top