[英]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.