ボディ ペインの中央にある別の fxml (main.fxml) に fxml (test.fxml) を呼び出そうとしています。実際には、main.fxml のコントローラー クラスでこれを行っています。いろいろな方法を試しても、中心要素をまったく設定できません。要件は、メインの fxml ファイルのツリー構造を右クリックして、さまざまな fxml ファイルを表示する必要があることです。
しかし、このメソッドを呼び出すと、「場所が必要です」という例外が発生します。何かしなければならないことはありますか?助けてください。
main.fxml
@FXML
TreeView<String> mainTree;
@FXML
BorderPane rootLayout;
@FXML
AnchorPane dynamicContent;
ContextMenu cntxtMenu;
//Method where i am trying to set main.fxml center body
public void showAttributeScreen(){
FXMLLoader loader = new FXMLLoader(scriptbuilder.controller.TestController.class.getResource("view/test.fxml"));
AnchorPane pane = new AnchorPane();
try{
pane = (AnchorPane) loader.load();
rootLayout.setCenter(pane);
}
catch(Exception e){
}
}
test.fxml
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" fx:controller="scriptbuilder.controller.TestController">
<Label alignment="BASELINE_CENTER" text="Hi" />
</AnchorPane>