JavaFX TabPane,Tab.setContent() doesn't work
<p>The problem is that i want to transfer an item between a <code>GridPane</code> and a <code>Tab</code>
so i am adding the item to the tab first.</p>

<p>Then i am adding the same item to the <strong>GridPane</strong>.Its works well until here.But then i want to add the item back to the tab and i am using  </p>

<pre><code>tab.setContent(item);
</code></pre>

<p>But it doesn't work.Neither the item is removed from the GridPane neither the item is added to the tab as content.Why is this happening??</p>

<blockquote>
  <p>The <strong>.java</strong> file:</p>
</blockquote>

<pre><code>package pack;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class Starter extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setScene(new Scene(new UI()));
        primaryStage.centerOnScreen();
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }

    /**
     * This class contains the graphical interface
     * 
     * @author Alexander
     *
     */
    public class UI extends BorderPane implements Initializable {

        @FXML
        private Tab tab;

        @FXML
        private Button item;

        @FXML
        private GridPane gridPane;

        @FXML
        private Button transferButton;

        boolean onGridPane = false;

        /**
         * Constructor
         */
        public UI() {
            FXMLLoader loader = new FXMLLoader(getClass().getResource("UI.fxml"));
            loader.setController(this);
            loader.setRoot(this);

            try {
                loader.load();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void initialize(URL location, ResourceBundle resources) {
            System.out.println("Main Controller has been initialized....");

            transferButton.setOnAction(a -&gt; {
                if (!onGridPane) {
                    gridPane.add(item, 0, 0);
                    onGridPane = true;
                    transferButton.setText("&lt;-Move to Tab");
                } else {
                    tab.setContent(item);
                    onGridPane = false;
                    transferButton.setText("Move to GridPane-&gt;");
                }
            });
        }

    }

}
</code></pre>

<blockquote>
  <p>And the <strong>.fxml</strong> file:</p>
</blockquote>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;?import javafx.geometry.Insets?&gt;
&lt;?import javafx.scene.control.Button?&gt;
&lt;?import javafx.scene.control.Label?&gt;
&lt;?import javafx.scene.control.Tab?&gt;
&lt;?import javafx.scene.control.TabPane?&gt;
&lt;?import javafx.scene.layout.BorderPane?&gt;
&lt;?import javafx.scene.layout.ColumnConstraints?&gt;
&lt;?import javafx.scene.layout.GridPane?&gt;
&lt;?import javafx.scene.layout.RowConstraints?&gt;
&lt;?import javafx.scene.text.Font?&gt;

&lt;fx:root prefHeight="322.0" prefWidth="538.0" type="BorderPane" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1"&gt;
   &lt;top&gt;
      &lt;TabPane prefHeight="141.0" prefWidth="538.0" style="-fx-border-color: red;" tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER"&gt;
        &lt;tabs&gt;
          &lt;Tab fx:id="tab" text="Tab"&gt;
               &lt;content&gt;
                  &lt;Button fx:id="item" mnemonicParsing="false" text="Moving Item" /&gt;
               &lt;/content&gt;
          &lt;/Tab&gt;
        &lt;/tabs&gt;
      &lt;/TabPane&gt;
   &lt;/top&gt;
   &lt;bottom&gt;
      &lt;GridPane fx:id="gridPane" gridLinesVisible="true" style="-fx-border-color: red;" BorderPane.alignment="CENTER"&gt;
        &lt;columnConstraints&gt;
          &lt;ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /&gt;
        &lt;/columnConstraints&gt;
        &lt;rowConstraints&gt;
          &lt;RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /&gt;
        &lt;/rowConstraints&gt;
      &lt;/GridPane&gt;
   &lt;/bottom&gt;
   &lt;right&gt;
      &lt;Button fx:id="transferButton" mnemonicParsing="false" text="Move to GridPane-&amp;gt;" BorderPane.alignment="CENTER"&gt;
         &lt;font&gt;
            &lt;Font size="16.0" /&gt;
         &lt;/font&gt;&lt;/Button&gt;
   &lt;/right&gt;
   &lt;padding&gt;
      &lt;Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /&gt;
   &lt;/padding&gt;
   &lt;center&gt;
      &lt;Label prefHeight="82.0" prefWidth="340.0" style="-fx-font-weight: bold; -fx-font-size: 15;" text="Above is a [TabPane] and Below is a [GridPane]" BorderPane.alignment="CENTER" /&gt;
   &lt;/center&gt;
&lt;/fx:root&gt;
</code></pre>