Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switching betweeen scenes #114

Open
Elvishbee opened this issue Apr 18, 2018 · 1 comment
Open

switching betweeen scenes #114

Elvishbee opened this issue Apr 18, 2018 · 1 comment

Comments

@Elvishbee
Copy link

public void start(Stage primaryStage) {
    window = primaryStage;

    //Button 1
    Label label1 = new Label("Welcome to the first scene!");
    Button button1 = new Button("Create Account");
    button1.setOnAction(e -> window.setScene(scene2));

    //Layout 1 - children laid out in vertical column
    VBox layout1 = new VBox(30);
    layout1.getChildren().addAll(label1, button1);
    scene1 = new Scene(layout1, 200, 200);

    GridPane grid = new GridPane();
    grid.setPadding(new Insets(10, 10, 10, 10));
    grid.setVgap(8);
    grid.setHgap(10);

    //Name Label - constrains use (child, column, row)
    Label nameLabel = new Label("Username:");
    GridPane.setConstraints(nameLabel, 0, 0);

    //Name Input
    TextField nameInput = new TextField("Bucky");
    GridPane.setConstraints(nameInput, 1, 0);

    //Password Label
    Label passLabel = new Label("Password:");
    GridPane.setConstraints(passLabel, 0, 1);

    //Password Input
    TextField passInput = new TextField();
    passInput.setPromptText("password");
    GridPane.setConstraints(passInput, 1, 1);

    //Login
    Button loginButton = new Button("Log In");
    GridPane.setConstraints(loginButton, 1, 2);

    //Add everything to grid
    grid.getChildren().addAll(nameLabel, nameInput, passLabel, passInput, loginButton);

    Scene scene2 = new Scene(grid, 300, 200);

    

    //Display scene 1 at first
    window.setScene(scene1);
    window.setTitle("Project");
    window.show();
}

it does not switch to the scene where i have my textfields, what can i do?

@Buchx
Copy link

Buchx commented Apr 18, 2018

Your button1.setOnAction tries to show scene2, which you first initialize at 4th bottom line, that would return you a null.

Move the button1.setOnaction below Scene scene2 = new Scene(grid, 300, 200); and then it should work.

So in the end it should look like this:

Scene scene2 = new Scene(grid, 300, 200);
button1.setOnAction(e -> window.setScene(scene2));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants