在HBox布局中加载数据,FXML



我正在使用javafx开发一个简单的应用程序。我遇到一个问题。我想用一些数据填充我的HBox布局,并希望在我的Controller类中这样做。我不知道如何将Controller类中的方法引用到FXML文件中的元素,这样,一旦我的应用程序启动并加载主窗口,HBox就会填充数据。我应该使用HBox元素的哪个属性?

这里有一些代码:

<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<Pane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gui.Controller" >
   <children>
      <HBox layoutX="386.0" layoutY="14.0" prefHeight="371.0" prefWidth="200.0" fx:id="hbox"  />
   </children>
</Pane>

只需修改Pane.getChildren()返回的ObservableList即可。

最新更新