I am doing a timeline project. I have successfully created a login system and menus for everything, but when I press the buttons I have done so it will open a new window(wit
Each FXML file is not necessarily a new Scene.
A fxml is just a view file with its root element as any of the Layouts provided by Javafx. It may have multiple Layouts(as a part of the root layout) and controls depending on your requirement.
To know more about fxml, you can view
Java vs JavaFX Script vs FXML. Which is better way of programming in JavaFX?
Tutorial on FXML
http://docs.oracle.com/javafx/2/fxml_get_started/jfxpub-fxml_get_started.htm
Now, once your FXML is ready, you can load it in different ways :
To help you understand the above points here is an example for each of them. Here, I am demonstrating a LoginController class which is a Controller for loading the FXML.
Example - 1
FXMLLoader loader = new FXMLLoader(LoginController.class.getResource("root.fxml"));
AnchorPane login = (AnchorPane) loader.load();
Scene scene = new Scene(login);
Example - 2
FXMLLoader loader = new FXMLLoader(LoginController.class.getResource("root.fxml"));
AnchorPane login = (AnchorPane) loader.load();
BorderPane borderPane = (BorderPane)scene.getRoot();
borderPane.setCenter(login);
Example - 3
FXMLLoader loader = new FXMLLoader(LoginController.class.getResource("root.fxml"));
AnchorPane login = (AnchorPane) loader.load();
Scene scene = new Scene(login);
stage.setScene(scene);//Stage loads the new scene, which has the layout of the fxml
N.B. For more details on how to access Stage/Scene on different controllers please go through
https://community.oracle.com/message/11251866