Hello guys,
I have gone mad because of this issue. I want to design a desktop app where I have a main window with side pane containing buttons. When a button is clicked another fxml document displays in the center of the main window (which is basically a Border Pane). Another thing, how can I put a close button on the sub window to close the displayed fmxl document? The code runs and displays the main window content, but crashes when I click on the button to display Page1. This is very basic code. I don't need complex solutions please.
Two pictures of what I need to design are attached.
Here is the code in my Main Class:
package main;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
private Stage primaryStage;
@Override
public void start(Stage primaryStage) throws Exception {
this.primaryStage = primaryStage;
showRootStage();
}
public static void main(String\[\] args) {
launch(args);
}
private void showRootStage() throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("Stage.fxml"));
Scene scene = new Scene(loader.load());
primaryStage.setScene(scene);
primaryStage.show();
}
This is the code in the main window controller (Stage document)
package main;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.layout.BorderPane;
public class Stage implements Initializable {
@FXML
private BorderPane rootStage;
@FXML
private void handleButtonAction(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(javafx.stage.Stage.class.getResource("Page1.fxml"));
BorderPane newScene = loader.load();
rootStage.setCenter(newScene);
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}

