1

I was wondering if there is a simple way to clone elements in FXML (such as textboxes) to display them more then one time.

Following situation:

I have a TabView and want to display on the first Tab elements X, on the second Tab elements Y and on the third Tab I want to display X and Y.

Dublicating the same fx:id is not allowed (Netbeans says) and exporting X and Y in different .fxml files, so that I just include them twice, neither works. Thats another problem.

How would you solve this ?

Salah Eddine Taouririt
  • 24,925
  • 20
  • 60
  • 96
hitchdiddy
  • 129
  • 1
  • 1
  • 5

2 Answers2

0

Make a new component with its own FXML. Then you can just include as many as you want.

One way to achieve this is to implement a custom java class that extends a javafx component (Pane or VBox for instance), then in the constructor of this class you load the FXML of its layout. With FXMLLoader you set the controller and root as the current component and you use the fx:root tag in FXML.

You'll have a component with a java class which will be the root and controller of its own FXML.

zenbeni
  • 7,019
  • 3
  • 29
  • 60
0

I would generally suggest splitting the whole .FXML into 3 different pieces which can be maintained seperately.

TabView, SplitPanes and all containers like this should be in a standalone FXML and each new pane in another one. In your case:

  • TabView = 1 FXML
  • Tab 1 = 1 FXML
  • Tab 2 = 1 FXML

You can export them in that way, but the elements need a container like HBox or something simple (like the Pane you need to create when you start SceneBuilder or your root Parent)

thatsIch
  • 828
  • 11
  • 23