title: JavaFX, pass parameters between tabs controller
body: <p>I looked for a solution anywhere before asking this question, if it already exists please report it.</p>
  
  <p>In practice I have this situation:</p>
  
  <p><a href="https://i.stack.imgur.com/nzeS4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nzeS4.jpg" alt="CLICK TO VIEW THE IMAGE"></a> </p>
  
  <p><strong>TabLayout.fxml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;JFXTabPane fx:id="tabbedPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefWidth="500.0" tabClosingPolicy="UNAVAILABLE" tabMinWidth="100.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.TAB.TabController" stylesheets="@tab.css"&gt;
  &lt;tabs&gt;
    &lt;Tab id="anagrafeTab" closable="false" text="Anagrafe"&gt;
      &lt;content&gt;
        &lt;fx:include fx:id="anagrafeL" source="/application/Anagrafe/AnagrafeLayout.fxml"/&gt;
       &lt;/content&gt;
    &lt;/Tab&gt;
    &lt;Tab id="visiteTab" closable="false" text="Visite"&gt;
       &lt;content&gt;
          &lt;fx:include fx:id="visiteL" source="/application/Visite/VisiteLayout.fxml"/&gt;
       &lt;/content&gt;&lt;/Tab&gt;
    &lt;Tab id="latteTab" closable="false" text="Produzione Latte"&gt; 
       &lt;content&gt;
          &lt;fx:include fx:id="latteL" source="/application/Latte/LatteLayout.fxml"/&gt;
       &lt;/content&gt;
    &lt;/Tab&gt;
    &lt;Tab id="partiTab" closable="false" text="Parti" &gt;
       &lt;content&gt;
           &lt;fx:include fx:id="partiL" source="/application/Parti/PartiLayout.fxml"/&gt;
       &lt;/content&gt;
    &lt;/Tab&gt;
  &lt;/tabs&gt;
  &lt;/JFXTabPane&gt;
  </code></pre>
  
  <p>A layout for every "include":</p>
  
  <ul>
  <li><code>AnagrafeLayout.fxml</code></li>
  <li><code>VisiteLayout.fxml</code></li>
  <li><code>LatteLayout.fxml</code></li>
  <li><code>PartiLayout.fxml</code></li>
  </ul>
  
  <p>Than I have a model and a controller for every Layout but an unique caller.</p>
  
  <pre><code>public class Tab {
  
  public Tab() {
      inizializza();
  }
  
  private void inizializza() {
      try {
          Stage stage = new Stage();
          stage.setTitle("Dati");
          stage.getIcons().add(new Image(getClass().getResourceAsStream("insert.png")));
  
          FXMLLoader loader = new FXMLLoader();
          loader.setLocation(getClass().getResource("TabLayout.fxml"));
          JFXTabPane root = (JFXTabPane) loader.load();
  
          Scene scene = new Scene(root,660,430);
          stage.setScene(scene);
  
          stage.show();
          //ScenicView.show(scene);
  
      } catch(Exception e) {
          e.printStackTrace();
      }
  
     }
  }
  </code></pre>
  
  <p>I need to pass an <code>ObservableList&lt;Visite&gt; data = FXCollections.observableArrayList();</code> to each controller.</p>
  
  <p>I do not really know how to do, and I would not use a single controller because they are quite long classes.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p><strong>TABController.java</strong></p>
  
  <pre><code>public class TabController implements Initializable {
  
  @FXML
  private TabPane tabbedPane;
  
  @Override
  public void initialize(URL arg0, ResourceBundle arg1) {
      assert tabbedPane != null : "fx:tabbedPane=\"in\" was not injected: check your FXML file 'TabLayout.fxml'.";
  
      tabbedPane.getSelectionModel().selectedItemProperty().addListener((ov, oldTab, newTab) -&gt; {
  
          if(tabbedPane.getSelectionModel().getSelectedIndex() != 0) {
              tabbedPane.getScene().getWindow().setWidth(1171);
              tabbedPane.getScene().getWindow().setHeight(700);
          } else {
              tabbedPane.getScene().getWindow().sizeToScene();
          }           
      });
    }
  }
  </code></pre>
  
  <p><strong>EDIT2</strong></p>
  
  <p>The 4 tabs have, as mentioned above, each his own model class.
  So I have 4 different lists, which are initially empty because they are filled dynamically since there is a table for each tab.
  The lists are created when the tabPane is called by a different internships.
  I need these lists because it may be the possibility of a previous load and I have to then pass this information to the controller.</p>
  
  <p>In practice, this happens:</p>
  
  <p>1)</p>
  
  <p>Call the function insert that creates empty lists loaded from the tables in the tab. The data is then stored in a database at the close.</p>
  
  <p>2)</p>
  
  <p>Call the function displays that calls the function insert with a specific flag that creates lists and takes the data from the database and sends them to the tables that can then be modified.</p>
  
  <p>I hope I was clear, I apologize for the ambiguity of the question precede</p>
  
  <p>Now I'm solving in this way</p>
  
  <pre><code>public class TabController implements Initializable {
  
  @FXML
  private TabPane tabbedPane;
  
  @FXML
  private VisiteController visiteLController;
  private ObservableList&lt;Visite&gt; dataVisite = FXCollections.observableArrayList();
  private ObservableList&lt;Visite&gt; dataDelVisite = FXCollections.observableArrayList();
  
  @FXML
  private LatteController latteLController;
  private ObservableList&lt;Latte&gt; dataLatte = FXCollections.observableArrayList();
  private ObservableList&lt;Latte&gt; dataDelLatte = FXCollections.observableArrayList();
  
  @FXML
  private PartiController partiLController;
  private ObservableList&lt;Parti&gt; dataParti = FXCollections.observableArrayList();
  private ObservableList&lt;Parti&gt; dataDelParti = FXCollections.observableArrayList();
  
  
  @Override
  public void initialize(URL arg0, ResourceBundle arg1) {
      assert tabbedPane != null : "fx:tabbedPane=\"in\" was not injected: check your FXML file 'TabLayout.fxml'.";
  
      tabbedPane.getSelectionModel().selectedItemProperty().addListener((ov, oldTab, newTab) -&gt; {
  
          if(tabbedPane.getSelectionModel().getSelectedIndex() != 0) {
              tabbedPane.getScene().getWindow().setWidth(1171);
              tabbedPane.getScene().getWindow().setHeight(700);
          } else {
              tabbedPane.getScene().getWindow().sizeToScene();
          }           
      });     
  
      visiteLController.setData(dataVisite, dataDelVisite);
      latteLController.setData(dataLatte, dataDelLatte);
      partiLController.setData(dataParti, dataDelParti);
   }
  }
  </code></pre>
  
  <p>and the set method obviously changed for each controller</p>
  
  <pre><code>    public void setData(ObservableList&lt;Visite&gt; data, ObservableList&lt;Visite&gt; dataDel) {
      this.data = data;
      this.dataDel = dataDel;
      liveSearh();
  }
  </code></pre>