如果我们有一个 Stage
那么 Scene
包括 2 个 Pane
第一个 Pane
包含 Button
,第二个 Pane
是空的
我们可以在第二个 Pane
中加载其他 fxml 文件吗?
fxml1: VBox
|_Pane1-->Button
|_Pane2
///////////////
fxml2: Pane--> Welcome to fxml 2
"when we click the button load the fxml2 inside Pane2 of fxml1"
然后点击之后
====我在尝试后终于找到了这个作品!====谢谢你们
@FXML Pane secPane;
public void loadFxml (ActionEvent event) {
Pane newLoadedPane = FXMLLoader.load(getClass().getResource("/application/fxml2.fxml"));
secPane.getChildren().add(newLoadedPane);
}
最佳答案
经过尝试,我终于找到了这个方法!
@FXML Pane secPane;
public void loadFxml (ActionEvent event) {
Pane newLoadedPane = FXMLLoader.load(getClass().getResource("/application/fxml2.fxml"));
secPane.getChildren().add(newLoadedPane);
}
关于java - 如何在 Pane 中加载 fxml 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33748127/