I have a GUI, made using JavaFX with FXML.
This GUI has a lot of components and not all of them are needed at one moment of time.
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.
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).
So. I have no need to have all 30 tabs in my node tree (I suppose they'll just "eat" memory and nothing more).
I want to manage the amount of tabs I have at each moment on my GUI.
The first simple solution I have is the following:
- Create an FXML file which contains the components for all cities
- During the initialization in the controller class, remove tabs, which aren't needed.
There are to problems I have with this solution. First, I don't know whether tabPane.getTabs().remove(index)
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.
The second solution I have is:
- Make a lot of FXMLs. One for all cities, one for each city and a one for each combination of cities.
But there will be way to many FXMLs, so this solution is also not useful.
The solution I dream for:
- Create an FXML file for each city and one for the main app with tabs.
- Load FXML city file content into a tab dynamically when needed.
So, if someone has any ideas on this task, or knows the solution, please help my with it...