JavaFX allows primary stages to swap out scenes. However, JavaFX stages don’t handle MenuBars directly. So what if you want to swap JavaFX scenes, but need to share one MenuBar between them? The trick is using a BorderPane as a root pane of your scene to hold a top JavaFx MenuBar and a central pane that gets swapped, instead of swapping the primary stage’s scene.
This example creates a Main class, a menu controller class, and three FXML files. The FXML files are a MenuBar, and two AnchorPanes that we swap between. All the custom code is included below for quick reference.