Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

need to embed child fxml inside parent fxml

Tags:

javafx-2

I am new to JavaFX and I want to know if there is way to place one fxml file as in child.fxml inside another say parent.fxml.

Why do i need this ? Idea is, i want create independent screens(small one) and write a parent fxml where we can add these child fxml to create a desired GUI, instead of one fxml where i dump all the controls.

If it's possible, please help with some dummy code or links. I have tried looking around for a while but did not get anything useful.

Thanks in advance for any help.

like image 460
Dil Avatar asked Jul 23 '13 07:07

Dil


People also ask

How do I add FXML to another FXML?

The <fx:include> tag can be used to include one fxml file into another. The controller of the included fxml can be injected into the controller of the including file just as any other object created by the FXMLLoader . This is done by adding the fx:id attribute to the <fx:include> element.

Can two FXML files have the same controller?

It's possible to use the same controller class for multiple FXML files, but your code will be really hard to follow, and it's a very bad idea. (Also note that using the fx:controller attribute, you will have a different controller instance each time you call FXMLLoader.

Where in a FXML file do I need to specify a controller class?

It is also possible to assign the controller class directly from the FXML file. In order to do that, you should first open your FXML file and add the following code on the first line of the file right after declarations. Example: Since my controller is inside the package name “view”, my fx: controller = “view.


1 Answers

If I understand correctly you want to use "fx:include" tag. Please refer the fxml reference

like image 181
Ramanuj Srivastava Avatar answered Sep 28 '22 19:09

Ramanuj Srivastava