Ответ 1
Я скорректировал код с ключом, который дал мне Энди. Я изменил объект pContent на AnchorPane вместо панели. Метод, который работает ниже:
public void showContentPane(String sURL){
//1. sURL can be something like "/GUI/home/master/MasterHome.fxml"
//2. getContentPane() returns following object: AnchorPane pContent
try {
URL url = getClass().getResource(sURL);
getContentPane().getChildren().clear();
//create new AnchorPane based on FXML file
AnchorPane n = (AnchorPane) FXMLLoader.load(url, ResourceBundle.getBundle("src.bundles.bundle", getLocale()));
//anchor the pane
AnchorPane.setTopAnchor(n, 0.0);
AnchorPane.setBottomAnchor(n, 0.0);
AnchorPane.setLeftAnchor(n, 0.0);
AnchorPane.setRightAnchor(n, 0.0);
getContentPane().getChildren().add(n);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
Подсказка: убедитесь, что в загруженном файле FXML вы не используете переменные фиксированной ширины или высоты.