r/JavaFX • u/DallasP9124 • Feb 29 '24
Help Use custom controls with markup instead of fx:include?
Starting to get into JavaFX and love it! Been getting into creating custom controls but am finding a pattern I am not too fond of. As far as my knowledge goes, the way you use custom controls in FXML is to us fx:include source="custom-control.fxml" , which really gets annoying to use. I would rather use my control name as the element, just as you would with HTML markup, which looks much nicer in my opinion.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane xmlns:fx="http://javafx.com/fxml">
<fx:include source="custom-control.fxml"/>
vs
<CustomControl/>
</BorderPane>
I already know how to do this in code but I would much rather not have to go down that route (mixing methodologies). Is there a way to use custom controls the same you would FXML markup?
I found this Oracle tutorial on creating custom controls and in the last example they show using the component just as I described but don't explain how at all (I realize the tutorial is super old and outdated).
Thank you much!
View all comments
Show parent comment
3
u/DallasP9124 Mar 01 '24
No he didn't. He is talking about creating a jar and using scene builder which was not mentioned at all in the OP. I was able to do exactly what I asked after help from @OddEstimate1627 pointed out the missing info from the Oracle tutorial. After going through that again, I was able to reference controls by name in FXML without having to create a whole separate jar or use scene builder.