title: JavaFX - Unique scene per stage
body: <p>I have a class that extends Application and calls the primary stage. This primary stage has a Next Button, that will call another stage (options stage). The options stage has a Previous Button. 
  I'd like to get the instance of the primary stage, in the state it was before the user clicked Next Button, for example: a textfield with input data or combobox with selected item.
  How can I do that?</p>
  
  <p>Main class:</p>
  
  <pre><code>public class MainClass extends Application {
  
      @Override
      public void start(Stage primaryStage) throws Exception {
  
          final FXMLLoader loader = new FXMLLoader(getClass().getResource("interfaceOne.fxml"));
          final Parent root = (Parent)loader.load();
          final MyController controller = loader.&lt;MyController&gt;getController();
  
          primaryStage.initStyle(StageStyle.TRANSPARENT);
          primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("icon.png")));
  
          Scene scene = new Scene(root);
          primaryStage.setScene(scene);
          Platform.setImplicitExit(false);
  
          controller.setStage(primaryStage);
          primaryStage.show();        
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  </code></pre>
  
  <p>}</p>
  
  <p>MyController:</p>
  
  <pre><code>public class MyController{
  
      // Some declarations ...
  
      Stage stage = null;
  
      public void setStage(Stage stage) {
         this.stage = stage;
      }
  
      // Next button's action
      @FXML
      public void handleNextAction(ActionEvent event) {
  
          try {  
  
              Parent root = FXMLLoader.load(getClass().getResource("optionInterface.fxml"));
  
              stage.initStyle(StageStyle.TRANSPARENT);
              stage.getIcons().add(new Image(getClass().getResourceAsStream("icon.png")));
              stage.setScene(new Scene(root));
              stage.show();
  
              // Hide the current screen
              ((Node)(event.getSource())).getScene().getWindow().hide();
  
          } catch (Exception exc) {
              System.out.println("Error: " + exc.getMessage());
          }
      }
  }
  </code></pre>
  
  <p>Options Controller:</p>
  
  <pre><code>public class OptionsController implements Initializable {
  
      public void handlePreviousAction(ActionEvent event) {
          try {
              Parent root = FXMLLoader.load(getClass().getResource("interfaceOne.fxml"));;
              MyController controller = MyController.getInstance();
  
              stage.initStyle(StageStyle.TRANSPARENT);
              stage.getIcons().add(new Image(getClass().getResourceAsStream("icon.png")));
              stage.setScene(new Scene(root));
  
              controller.setStage(stage);
              controller.isLocationLoaded(false);
              stage.show();
  
              // Hide the current screen
              ((Node)(event.getSource())).getScene().getWindow().hide();
  
          } catch (IOException exc) {
              System.out.println("Error: " + exc.getMessage());
  
          }
      }
  }
  </code></pre>