I'm asking regarding the relationships between Nodes, Scenes and Parents. I'm actually studying JavaFX and is difficult change scenes in the same frame. I founded a way for do that, but actually I don't know how it works. Can you help me figure it out ?
I tried looking for on the Java reference, on youtube and also writing on google the keyword "Scenes Parent" but I didn't found anything that helped me.
public class SceneCreator {
// launching the new scene based on the .fxml file name passed in the argument as a String variable
// building the scene and setting the value for the instance variable loader
public static void launchScene (String sceneName) throws IOException {
// Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
FXMLLoader loader = new FXMLLoader(Main.class.getResource(sceneName));
Main.setRoot(loader.load());
Scene scene = new Scene(Main.getRoot());
Main.getStage().setScene(scene);
Main.getStage().show();
@FXML
private void sphereClick() throws IOException{
System.out.println("Sphere button clicked");
SceneCreator.launchScene("sphere.fxml");
}
Welcome to StackOverFlow, Please search very thouroghly before asking a question, but to target the answer here:
The JavaFX scene
graph is part of the top layer and is the starting point for constructing a JavaFX application.
It is a hierarchical tree of nodes that represents all of the visual elements of the application’s user interface. It can handle input and can be rendered, refer to the picture
A single element in a scene graph is called a node
. Each node
has an ID
, style class
, and bounding volume
.
each node in a scene graph has a single parent
and zero or more children
please read the following book it is around 70 pages but its very helpful, and since you are studying it, there is not time wasted https://docs.oracle.com/javase/8/javafx/JFXST.pdf
Refer to stackoverflow questions, they can be really helpful and they target your very question, such as this one:
How to swap screens in a javafx-application in the controller-class?
or this one