Program entry point:
public class App extends Application {
@Override
public void start(Stage primaryStage) throws IOException {
Parent startScreen
= FXMLLoader.load(getClass().getResource("MainScreen.fxml"));
Scene scene = new Scene(startScreen);
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
MainScreenController
public class MainScreenController implements Initializable{
private static AnchorPane contentBox;
@FXML
private AnchorPane paneContent;
public MainScreenController() throws IOException {
this.paneContent = FXMLLoader.load(getClass().getResource("Home.fxml"));
}
@Override
public void initialize(URL url, ResourceBundle rb) {
MainScreenController.contentBox = this.paneContent;
}
public static AnchorPane getContentBox(){
return MainScreenController.contentBox;
}
}
Then MainScreen.fxml needs to have MainScreenController as controller and also needs to contain an AnchorPane with fx:id paneContent.
Then from anywhere in your program you can call getContentBox() and use .set() to change the screen.