Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constants in an FXML file

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!

like image 738
sorbet Avatar asked May 25 '14 23:05

sorbet


People also ask

What does FXML stand for?

FX Markup Language. In the same way that HTML is for Hypertext Markup Language, and many more acronyms that end in ML .

What is the purpose of the attribute FX controller?

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.

Do I need to use FXML?

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.


1 Answers

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.

screenshot

I'll go file a bug report.

Edit: Bug is fixed.

like image 79
sorbet Avatar answered Oct 20 '22 17:10

sorbet