Couldn't find any examples on this. How do I define constants in an FXML file?
For example (where CONTENT_SPACING
is the constant I want to create):
<VBox fx:controller="myapp.Controller" xmlns:fx="http://javafx.com/fxml" alignment="center" spacing="20">
<fx:define>
<Double fx:id="CONTENT_SPACING" fx:value="200"/>
</fx:define>
<VBox fx:id="content" spacing="$CONTENT_SPACING">
<!-- My window contents would go here -->
</VBox>
</VBox>
My code would benefit in readability if this was possible. Thanks!
FX Markup Language. In the same way that HTML is for Hypertext Markup Language, and many more acronyms that end in ML .
As discussed earlier, the fx:controller attribute allows a caller to associate a "controller" class with an FXML document. A controller is a compiled class that implements the "code behind" the object hierarchy defined by the document.
You can not write a single FXML file but instead would have to write many single files, each would build a small part of the custom component. This is not really handy to manage, so most developers choose to do it without FXML, directly in code.
Well, this is a bit embarrassing. It was valid FXML all along, but my IDE (IntelliJ IDEA) keeps telling me it's not. The code itself runs fine.
I'll go file a bug report.
Edit: Bug is fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With