I have a FXML document containing the visual basis of my JavaFX project and I want to make an own Topbar (where the X, minumum/maximum, etc... is) by using a Pane. But my program will have multiply pages (scenes) and to keep the code clean, I wanted to make the Custom-Topbar as a separate class (an component object kinda). I just don't know how I should implement this class into the FXML basis I use (I am using Scene Builder).
Option 1
If the toolbar is always there you can have a main fxml file with the toolbar and a container. Then load content from other fxmls and place that content in the container. To switch pages switch the content of the container (and not the scene).
Option 2
Create an fxml file with just the toolbar. Then use the <fx: include />
tag in your other fxmls to include the toolbar. This is like a "component".
Edit : This is how option 2 can work in practice.
Say toolbar.fxml
is the name of the fxml file containing only the toolbar.
Simply include <fx:include source="toolbar.fxml"/>
in an other fxml file to incldue the toolbar at that location. See here for more information.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.