title: JavaFX changing scene not working
body: <p>I'm trying to switch scenes in JavaFX. I've created 3 scenes so far - login screen, profile and register. For some reason I can't switch from login screen to profile. The "Register" button in login screen is working, as well as "Back" button in the register screen. When clicking the "Log in" button, nothing is happening. What am I missing? Here's the main class:</p>
  
  <pre><code>import javafx.application.Application;
  import javafx.scene.Scene;
  import javafx.stage.Stage;
  import jedzenie.windows.LogInScreen;
  import jedzenie.windows.ProfileInfoScreen;
  import jedzenie.windows.RegisterScreen;
  
  
  public class App extends Application
  {
  
      Stage stage;
      Scene scene, scLogIn;
      LogInScreen logInScreen;
      RegisterScreen regis;
      ProfileInfoScreen profileScreen;
  
      @Override
      public void start(Stage primaryStage){
          primaryStage.setTitle("FoodCalc");
          stage = primaryStage;
  
  
          logInScreen = new LogInScreen(this);
          scLogIn = new Scene(logInScreen, 400, 400);
          scLogIn.getStylesheets().add(getClass().getResource("logInScreen.css").toExternalForm());
          primaryStage.setScene(scLogIn);
  
          primaryStage.show();
  
      }
  
  
      public void moveToRegisterScreen(){
          regis = new RegisterScreen(this);
          Scene scRegister = new Scene(regis, 575, 250);
          scRegister.getStylesheets().add(getClass().getResource("registerScreen.css").toExternalForm());
          stage.setScene(scRegister);
      }
  
  
      public void logOut(){
          stage.setScene(scLogIn);
      }
  
  
      public void logIn(){
          profileScreen = new ProfileInfoScreen(this);
          Scene scProfile = new Scene(profileScreen, 500, 400);
          scProfile.getStylesheets().add(getClass().getResource("registerScreen.css").toExternalForm());
          stage.setScene(scProfile);
  
      }
  
  
      public static void main( String[] args )
      {
          launch(args);
      }
  
  
  }
  </code></pre>
  
  <p>The LogInScreen class:</p>
  
  <pre><code>import javafx.event.ActionEvent;
  import javafx.geometry.HPos;
  import javafx.geometry.Pos;
  import javafx.scene.control.Button;
  import javafx.scene.control.Label;
  import javafx.scene.control.PasswordField;
  import javafx.scene.control.TextField;
  import javafx.scene.layout.GridPane;
  import jedzenie.app.App;
  
  public class LogInScreen extends GridPane {
  
  App main;
  
  public LogInScreen(App main){
      this.main = main;
  
      setAlignment(Pos.CENTER);
      //setGridLinesVisible(true);
  
      setVgap(15);
      setHgap(10);
  
      Label welc = new Label("Welcome to FoodCalc. Please log in or register.");
      add(welc, 0, 0, 2, 1);
  
      Label lbUser = new Label("Username: ");
      add(lbUser, 0, 1);
      TextField tfUser = new TextField();
      add(tfUser, 1, 1);
  
      Label lbPass = new Label("Password: ");
      add(lbPass, 0, 2);
      PasswordField pfPass = new PasswordField();
      add(pfPass, 1, 2);
  
      Button logIn = new Button("Log in");
      add(logIn, 1, 3);
      setHalignment(logIn, HPos.RIGHT);
      logIn.setOnAction((ActionEvent e) -&gt; {
          main.logIn();
      });
  
      Button register = new Button("Register");
      add(register, 1, 4);
      setHalignment(register, HPos.CENTER);
      register.setOnAction((ActionEvent e) -&gt; {
          main.moveToRegisterScreen();
      });
  
  
  }
  
  
  
  }
  </code></pre>
  
  <p>And the RegisterScreen class:</p>
  
  <pre><code>import javafx.event.ActionEvent;
  import javafx.geometry.Insets;
  import javafx.geometry.Pos;
  import javafx.scene.control.Button;
  import javafx.scene.control.ComboBox;
  import javafx.scene.control.Label;
  import javafx.scene.control.PasswordField;
  import javafx.scene.control.TextField;
  import javafx.scene.layout.BorderPane;
  import javafx.scene.layout.GridPane;
  import javafx.scene.layout.HBox;
  import jedzenie.app.App;
  
  public class RegisterScreen extends BorderPane {
  
      App main;
      Button register;
      ComboBox age;
      PasswordField pfPass, pfConfPass;
  
      public RegisterScreen(App main){
          this.main = main;
          setCenter(gridPane());
          setBottom(hbox());
          setPadding(new Insets(25,25,25,25));
      }
  
      GridPane gridPane() {
          GridPane gp = new GridPane();
  
          gp.setGridLinesVisible(true);
          gp.setVgap(15);
          gp.setHgap(10);
          gp.setAlignment(Pos.CENTER);
  
          Label lbUser = new Label("Username: ");
          gp.add(lbUser, 0, 1);
          TextField tfUser = new TextField();
          gp.add(tfUser, 1, 1);
  
          Label lbPass = new Label("Password: ");
          gp.add(lbPass, 0, 2);
          pfPass = new PasswordField();
          gp.add(pfPass, 1, 2);
  
          Label lbConfPass = new Label("Confirm Password: ");
          gp.add(lbConfPass, 0, 3);
          pfConfPass = new PasswordField();
          gp.add(pfConfPass, 1, 3);
  
          Label lbEmail = new Label("Email: ");
          gp.add(lbEmail, 0, 4);
          TextField tfEmail = new TextField();
          gp.add(tfEmail, 1, 4);
  
          Label lbSex = new Label("Sex: ");
          gp.add(lbSex, 2, 1);
          ComboBox cbSex = new ComboBox();
          gp.add(cbSex, 3, 1);
  
          Label lbAge = new Label("Age: ");
          gp.add(lbAge, 2, 2);
          ComboBox cbAge = new ComboBox();
          gp.add(cbAge, 3, 2);
  
          Label lbWeight = new Label("Weight: ");
          gp.add(lbWeight, 2, 3);
          TextField tfWeight = new TextField();
          gp.add(tfWeight, 3, 3);
  
          return gp;
      }
  
      HBox hbox(){
          HBox hbox = new HBox(10);
  
  
          Button back = new Button("Back");
          hbox.getChildren().add(back);
          back.setOnAction((ActionEvent e) -&gt;{
              main.logOut();
          });
  
          Button register = new Button("Register");
          hbox.getChildren().add(register);
  
  
          return hbox;
      }
  
  
  }
  </code></pre>
  
  <p>I've been trying too search for a difference between the methods and their implementation in the working ones and the one that doesn't work. Still can't find the reason.</p>
  
  <p>EDIT: Sorry I didn't notice I haven't put the ProfileInfoScreen class. Here it is:</p>
  
  <pre><code>import javafx.event.ActionEvent;
  import javafx.geometry.Insets;
  import javafx.scene.control.Button;
  import javafx.scene.control.Label;
  import javafx.scene.layout.BorderPane;
  import javafx.scene.layout.VBox;
  import jedzenie.app.App;
  
  public class ProfileInfoScreen extends BorderPane {
  
      App main;
      Insets ins = new Insets(10,10,10,10);
  
      public ProfileInfoScreen(App main){
          this.main = main;
          setPadding(ins);
          setTop(lbWelcome);
          setLeft(vbox());
  
      }
  
      Label lbWelcome = new Label("Welcome, " + "XXXXXXXXXXX");
  
      VBox vbox(){
  
      VBox vbox = new VBox();
      vbox.setSpacing(10);
      vbox.setPadding(ins);
  
      Button btWeight = new Button("Change weight");
      vbox.getChildren().add(btWeight);
      btWeight.setOnAction((ActionEvent e) -&gt; {
          //XXXXXXXXXX
  
      });
  
      return vbox;
  
      }
  }
  </code></pre>