简体   繁体   English

JavaFX使用控制器类添加对象

[英]JavaFX add objects with controller class

I have a JavaFX FXML which includes a ScrollPane , after the Application launches it gets Information out of the Internet , and with that it creates 500 HBoxes which contain the Information in three String and an Icon , but how can I create JavaFX ojects inside the controller class and can I use a fxml template for that? 我有一个JavaFX FXML ,其中包含ScrollPane ,在应用程序启动后,它从Internet获取信息,并使用它创建500个HBox,其中的信息包含三个String和一个Icon ,但是如何在controller内部创建JavaFX对象class ,我可以fxml使用fxml template吗? For easier understanding, it works like a App Store that creates a object for each App 为了更容易理解,它就像App Store一样为每个App创建一个对象

You would have to bind your parent container (BorderPane, AnchorPane, or whatever you use) in the controller and then you can let your controller implement the Initializable interface and the needed method void initialize(URL location, ResourceBundle resources) . 您将必须在控制器中绑定父容器(BorderPane,AnchorPane或您使用的任何容器),然后可以让控制器实现Initializable接口,并使用所需的方法void initialize(URL location, ResourceBundle resources)

In this method, you can add your HBoxes by using parent.getChildren().add(myHbox) . 在此方法中,可以使用parent.getChildren().add(myHbox)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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