title: How to load content to JavaFX tabs dynamically?
body: <p>I have a GUI, made using JavaFX with FXML.</p>
  
  <p>This GUI has a lot of components and not all of them are needed at one moment of time.</p>
  
  <p>For example, imagine a GUI that receives from its server part a list of cities.
  Each city is described on its own tab (and described with a lot of nodes). The set of cities contains 30 elements.</p>
  
  <p>When the GUI is launched, it asks the server for a list of the cities.
  The server returns a random "sub-set" of cities (so, it can be Moscow + Riga + New York or St.Petersburg + Tokyo, or only Amsterdam, or all 30 cities in one set).</p>
  
  <p>So. I have no need to have all 30 tabs in my node tree (I suppose they'll just "eat" memory and nothing more).</p>
  
  <p>I want to manage the amount of tabs I have at each moment on my GUI.</p>
  
  <p>The first simple solution I have is the following: </p>
  
  <ol>
  <li>Create an FXML file which contains the components for all cities</li>
  <li>During the initialization in the controller class, remove tabs, which aren't needed. </li>
  </ol>
  
  <p>There are to problems I have with this solution. First, I don't know whether <code>tabPane.getTabs().remove(index)</code> really removes the tab and all its content from the nodes tree. Second, all unneeded tabs will be initializated before they will be removed, so they'll use memory and resources anyway, and my GUI can be a slower than it has to be.</p>
  
  <p>The second solution I have is: </p>
  
  <ol>
  <li>Make a lot of FXMLs. One for all cities, one for each city and a one for each combination of cities.</li>
  </ol>
  
  <p>But there will be way to many FXMLs, so this solution is also not useful.</p>
  
  <p>The solution I dream for: </p>
  
  <ol>
  <li>Create an FXML file for each city and one for the main app with tabs.</li>
  <li>Load FXML city file content into a tab dynamically when needed.</li>
  </ol>
  
  <p>So, if someone has any ideas on this task, or knows the solution, please help my with it...</p>