Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javafx 如何使用代码将组件添加到fxml场景中_Javafx - Fatal编程技术网

Javafx 如何使用代码将组件添加到fxml场景中

Javafx 如何使用代码将组件添加到fxml场景中,javafx,Javafx,我使用的是JavaFX,场景由fxml文件加载 FXMLLoader loader = new FXMLLoader(); Parent rootNode = (Parent) loader.load(fxmlFile); setScene(new Scene(rootNode)); stage.setScene(scene); 如何将组件添加到此场景?例如,如何在代码中添加“按钮/代码>”到“代码>场景?让我们考虑一下,你有 BrordPANE作为FXML的根>代码>元素。现在,您可以继续这

我使用的是
JavaFX
,场景由
fxml
文件加载

FXMLLoader loader = new FXMLLoader();
Parent rootNode = (Parent) loader.load(fxmlFile);
setScene(new Scene(rootNode));
stage.setScene(scene);

如何将
组件
添加到此
场景
?例如,如何在代码中添加“<代码>按钮/代码>”到“代码>场景?

让我们考虑一下,你有<代码> BrordPANE<代码>作为FXML的<代码>根>代码>元素。现在,您可以继续这样做:

FXMLLoader loader = new FXMLLoader();
Parent rootNode = (Parent) loader.load(fxmlFile);
Button button = new Button();
((BorderPane) rootNode).setCenter(button);
setScene(new Scene(rootNode));
stage.setScene(scene);

非常感谢。我可以在创建场景时和stage.show()方法之后编辑场景组件吗?