Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have to return a Scene from another method or create a Scene within the "Start", and set the Scene on stage. For example:</p> <pre><code>public static Scene secondScene(final Stage primaryStage){ BorderPane pane = new BorderPane(); Label l = new Label("Second Scene"); pane.setCenter(l); //let's say I have a button that changes back to original stage Button b = new Button("Main stage"); b.setOnAction(new EventHandler&lt;ActionEvent&gt;(){ public void handle(ActionEvent t){ // create your own Scene and then set it to primaryStage primaryStage.setScene(new Scene ... ); } }); return new Scene(pane, 300, 300); } </code></pre> <p>Then on your start method:</p> <pre><code>@Override public void start(Stage primaryStage){ BorderPane mainPane = new BorderPane(); Button b = new Button("Register"); mainPane.setCenter(b); b.setOnAction(new EventHandler&lt;ActionEvent&gt;(){ public void handle(ActionEvent t){ primaryStage.setScene(secondScene(primaryStage)); } }); primaryStage.setScene(new Scene(mainPane, 300,300)); primaryStage.show(); } </code></pre> <p>This will change to "SecondScene" when the button is pressed.</p> <p>EDIT //////////////////////////////////////// BASICALLY:</p> <p>you need to pass in primaryStage as an argument to SecondScene in order to set another Scene onto it. What you could do in this case is, make a method that outputs the main scene and then set it using that.</p> <pre><code>public static Scene mainScene(final Stage primaryStage){ ..... return new Scene(...); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload