我正在设计一个 javaFX 应用程序。我正在努力在 BorderPanes 之间切换。我已经设计了两个页面(FXML 文件),第一个是主页,其中包含一些容器,如(VBox、BorderPane 等)。第二个仅包含一个 BorderPane。如何在第一页的 BorderPane 和第二页的 BorderPane 之间切换?
这是主类代码
package main;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class MainMethod extends Application{
private Stage primaryStage;
private VBox MainLayout;
private AnchorPane submain;
@Override
public void start(Stage primaryStage) throws IOException{
this.primaryStage = primaryStage;
this.primaryStage.setTitle("Nursery");
showMainView();
showMainPane();
}
private void showMainView() throws IOException{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainMethod.class.getResource("../controller/Add_child.fxml"));
MainLayout = loader.load();
Scene secne = new Scene(MainLayout);
primaryStage.setScene(secne);
primaryStage.show();
}
private void showMainPane() throws IOException{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainMethod.class.getResource("../controller/Add_ChildPane.fxml"));
VBox mainitems = loader.load(); // I am Struggling here I think
}
public static void main (String[] args){
System.out.println("sfdf");
launch(args);
}
}