Answer the question
In order to leave comments, you need to log in
How to change the scene in javaFX, through the controller?
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.*;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
primaryStage.setTitle("Hallo");
Parent menuRoot = FXMLLoader.load(getClass().getResource("menuScene.fxml"));
Parent firstRoot = FXMLLoader.load(getClass().getResource("firstScene.fxml"));
Scene scene = new Scene(menuRoot, 600, 400);
primaryStage.setMinHeight(600);
primaryStage.setMinWidth(400);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) throws IOException, ClassNotFoundException {launch(args);}
}
Answer the question
In order to leave comments, you need to log in
Make primaryStage static, from the controller, pull primaryStage.setScene(desired scene);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question