Multiple controllers for a single FXML file

I have one fxml file managed by one controller. I want to split the controller into several parts, as if it were placed in one controller, it makes a long code. Unfortunately, the fx: controller can only be placed in the root. Are there any suggestions for me how to separate the controller?

+4
source share
3 answers

I recommend creating custom controls - use several smaller FXML files rather than one large FXML file.

Here is a tutorial:

http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm

+8
source

When loading your FXML markup, there is only one condition for having one controller specified for your scene graph. You can download other FXML markup files and socket controllers, but I don’t think you are asking.

In my opinion, it does not matter.

You can write any number of classes in any number of files and associate them with your controller class in the same way that any Java class can interact with any other Java class.

I really can't come up with any particularly good reason why it would be useful to specify several controllers for the scene graph at boot time.

+1
source

You can add the fxml file as a node to another fxml, as with different controllers with the inclusion option in the scene builder

0
source

Source: https://habr.com/ru/post/1484010/


All Articles