title: Opening a TabPane when button is clicked from another view
body: <p>I have two separate views one which contains a button say <strong>view A</strong> and another a TabPane with 3 tabs call it <strong>view B</strong>. These two views are controlled by two separate view controller classes. I want to be able to click a button in <strong>view A</strong> and be able to to open a specific tab in <strong>view B's</strong> TabPane.</p>
  
  <p>So far I have tried extending the controller for <strong>view A</strong> with <strong>view B</strong> such that I can get the TabPane defined in <strong>view B's</strong> controller then call <code>myTabPane.getSelectionModel().select(myTab);</code> however this hasn't worked as it throws a NullPointerException.</p>
  
  <p>My question is it possible to click a button in <strong>view A</strong> such that it opens <strong>view B</strong> and opens a specific Tab on <strong>view B's</strong> TabPane.</p>
  
  <p>I have also looked at these links with no luck 1. <a href="https://stackoverflow.com/questions/6902377/javafx-tabpane-how-to-set-the-selected-tab">setting selected tab</a>, 2. <a href="https://stackoverflow.com/questions/20955633/how-to-switch-through-tabs-programmatically-in-javafx">switch through tabs programatically</a>, 3. <a href="https://stackoverflow.com/questions/24299724/switch-between-tabs-in-tabpane">switch between tabs in tabpane</a></p>
  
  <p><a href="https://i.stack.imgur.com/DwQWT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DwQWT.png" alt="view A"></a></p>
  
  <p>Lets say the above image is <strong>view A</strong> and when u click right it should open <strong>view B</strong> and open a specific tab in <strong>view B's</strong> TabPane.</p>
  
  <p><a href="https://i.stack.imgur.com/Miyle.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Miyle.png" alt="view B"></a></p>
  
  <p>Lets say the above image is <strong>view B</strong> and when the button right on <strong>view A</strong> is clicked it should open <strong>view B</strong> and set the tab to tab C.</p>
  
  <pre><code>import java.net.URL;
  import java.util.ResourceBundle;
  import javafx.fxml.Initializable;
  import java.net.URL;
  import java.util.ResourceBundle;
  import javafx.event.ActionEvent;
  import javafx.fxml.FXML;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Node;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.stage.Stage;
  import javafx.scene.control.SelectionModel;
  
  public class SucessfulCreateProjectViewController extends AdminViewController {
  
  
   @FXML
   private Button OkButton;
  
  @FXML
  void handleCreateTasksButtonAction(ActionEvent event) {
  
  
  try{
      FXMLLoader fxmlLoader = new FXMLLoader();
      fxmlLoader.setLocation(getClass().getResource("AdminView.fxml"));
      Scene scene = new Scene(fxmlLoader.load());
      Stage stage = new Stage();
      stage.setScene(scene);
      stage.show();
      AdminTabPane.getSelectionModel().select(1);; 
  
     }catch(Exception e){
  
      ErrorHandlerController.infoBox("Error Opening AdminPage", "Fail", null);
      e.printStackTrace();
     }
  
  }
  
  @FXML
  void handleOKButtonAction(ActionEvent event) {
  
    Stage stage = (Stage) OkButton.getScene().getWindow();
    stage.close();
  
  }
  
  @Override
  public void initialize(URL url, ResourceBundle rb) {
      // TODO
  }    }
  </code></pre>