Stage will not stay maximized when changing scenes

324 views Asked by At

I'm extremely new to programming. I'm using JavaFX and NetBeans IDE 8.0.2 to write a simple math program. I'm trying to change scenes in the same stage, and my code works but the stage will not stay maximized once the scenes have changed. I've tried everything i could think of to keep it maximized or to restore it to maximized i.e. stage.setMaximized(true); after the next scene is switched, but none of the code is working. I created a simple example of my problem. Does anyone have any tips for me in anyway? Thank you.

public class ProblemExample extends Application
{

    final double WIDTH = 600;
    final double HEIGHT = 600;

    Stage stage;
    Scene scene1, scene2;
    Pane pane1, pane2;

    public static void main(String[] args)
    {
        Application.launch(args);
    }

    @Override
    public void start(Stage primaryStage)
    {
        stage = primaryStage;
        pane1 = new Pane();
        pane2 = new Pane();

        getuiPane1();
        getuiPane2();

        scene1 = new Scene(pane1, WIDTH, HEIGHT);
        scene2 = new Scene(pane2, WIDTH, HEIGHT);
        stage.setTitle("Example");
        stage.setScene(scene1);
        stage.setMaximized(true);
        stage.show();
    } 

    public void getuiPane1()
    {
        Text nextText = new Text(300, 300, "Next >>");
        pane1.getChildren().add(nextText);

        nextText.setOnMouseClicked(e ->
        {
            if (e.getSource() == nextText)
            {
                stage.setScene(scene2);
            } else
            {
                stage.setScene(scene1);
            }
        }
        );
    }

    public void getuiPane2()
    {
        Text backText = new Text(300, 300, "<< Back");
        pane2.getChildren().add(backText);

        backText.setOnMouseClicked(e ->
        {
            if (e.getSource() == backText)
            {
                stage.setScene(scene1);
            } else
            {
                stage.setScene(scene2);
            }
        }
        );
    }
}
0

There are 0 answers