title: How to close tab when content is displayed in new window in JavaFX
body: <p>I have this context menu with option to display tab content into new window and closing TabPane tab:</p>
  
  <pre><code>MenuItem item5 = new MenuItem("Open Tab In Stand-Alone Window");
          item5.setOnAction(new EventHandler&lt;ActionEvent&gt;()
          {
              @Override
              public void handle(ActionEvent e)
              {
                  System.out.println("Open Tab In Stand-Alone Window");
                  Node test = tab.getContent();
  
                  NavMenu.standAloneTab(test);
                  tabPane.getTabs().remove(tab);
  
              }
          });
  </code></pre>
  
  <p>The new dialog with tab content:</p>
  
  <pre><code>public static void standAloneTab(Node tab)
      {
          final int xSize = 640;
          final int ySize = 480;
          final Color backgroundColor = Color.WHITESMOKE;
  
          Stage newConnDialog = new Stage();
          newConnDialog.initModality(Modality.WINDOW_MODAL);
  
          GridPane grid = new GridPane();
          grid.setAlignment(Pos.CENTER);
          grid.setHgap(10);
          grid.setVgap(10);
          grid.setPadding(new Insets(20, 20, 20, 20));
  
          grid.add(tab, 0, 0);
  
          Scene aboutDialogScene = new Scene(grid, xSize, ySize, backgroundColor);
          newConnDialog.setScene(aboutDialogScene);
          newConnDialog.show();
      }
  </code></pre>
  
  <p>When I select <code>Open Tab In Stand-Alone Window</code> new window appears with the content of the tab but the old tab is not closed. If I call <code>tabPane.getTabs().remove(tab);</code> to close the tab the new window is empty.</p>
  
  <p>How I can close the tab without deleting the content?</p>
  
  <p><em><strong>EDIT</em></strong></p>
  
  <p>I updated the code this way:</p>
  
  <pre><code>MenuItem item5 = new MenuItem("Open Tab in Stand-alone Window");
      item5.setOnAction(new EventHandler&lt;ActionEvent&gt;()
      {
          @Override
          public void handle(ActionEvent e)
          {
              System.out.println("Open Tab In Stand-Alone Window");
              Node openedTab = tab.getContent();
  
              NavMenu.standAloneTab(tabPane, openedTab);
              //tabPane.getTabs().remove(tab);
  
          }
      });
  </code></pre>
  
  <p>And the new dialog:</p>
  
  <pre><code>public static void standAloneTab(final TabPane tabPane, final Node tab)
      {
  
          Stage newConnDialog = new Stage();
          newConnDialog.initModality(Modality.WINDOW_MODAL);
  
          newConnDialog.setOnShown(new EventHandler&lt;WindowEvent&gt;()
          {
              @Override
              public void handle(WindowEvent t)
              {
                  tabPane.getTabs().remove(tab);
              }
          });
  
          GridPane grid = new GridPane();
          grid.setAlignment(Pos.CENTER);
          grid.setHgap(10);
          grid.setVgap(10);
          grid.setPadding(new Insets(20, 20, 20, 20));
  
          grid.add(tab, 0, 0);
  
          Scene aboutDialogScene = new Scene(grid, 700, 500, Color.WHITESMOKE);
          newConnDialog.setScene(aboutDialogScene);
          newConnDialog.show();
      }
  </code></pre>
  
  <p>I updated the code but I get the same result.</p>