setCenter替换整个场景

setCenter替换整个场景

本文介绍了JavaFX borderpane.setCenter替换整个场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将FXML加载到FXML中。主要的FXML有一个borderpane,第二个包含一个VBox。我用FXMLLoader加载这两个。当我尝试设置boarderpane的中心时,整个屏幕将被第二个FXML取代。这是代码

I'm trying to load a FXML into a FXML. The main FXML has a borderpane, and the second contains a VBox. I load both of these with the FXMLLoader. When I try to set the center of the boarderpane, the entire screen gets replaced with the second FXML. Here is the code

BorderPane riskAnalysis = new BorderPane((BorderPane) FXMLLoader.load(getClass().getResource("./proposaldevelopment/riskAnalysis.fxml")));
VBox center = new VBox((VBox) FXMLLoader.load(getClass().getResource("./proposaldevelopment/openRiskAssessmentVbox.fxml")));
riskAnalysis.setCenter(center);
root = riskAnalysis;

stage.getScene().setRoot(root);

任何可能导致此问题的想法?我也尝试制作一个新标签并将其放入边框中心,结果相同。

Any ideas that could cause this? I also tried making a new label and putting that into the borderpane center with the same result.

推荐答案

尝试

BorderPane riskAnalysis = (BorderPane) FXMLLoader.load(getClass().getResource("./proposaldevelopment/riskAnalysis.fxml"));
VBox center = (VBox) FXMLLoader.load(getClass().getResource("./proposaldevelopment/openRiskAssessmentVbox.fxml"));
riskAnalysis.setCenter(center);
stage.getScene().setRoot(riskAnalysis);

这篇关于JavaFX borderpane.setCenter替换整个场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 17:57