Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use arithmetic expression in FXML?

Tags:

java

javafx

fxml

I hoped for a feature that would allow me to work with numbers inside the FXML. For example, tried to define the height of one element to be equal to a constant and the height of the second element to be equal to the same constant multiplied by 2 (i.e. constant * 2). Is it possible to do it in FXML at all or do I need to do this part of view build-up inside the controller (which I would like to avoid)?

like image 580
Radosław Łazarz Avatar asked Mar 26 '15 16:03

Radosław Łazarz


People also ask

What is the full form of FXML?

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

What is xmlns FX?

The xmlns:fx attribute is always required and specifies the fx namespace. The remainder of the code controls the alignment and spacing of the grid pane. The alignment property changes the default position of the grid from the top left of the scene to the center.


1 Answers

Yes, it is possible:

<?import java.lang.Double?>

...

<fx:define>
    <Double fx:id="xHeight" fx:value="100" />
</fx:define>

...

<Label fx:id="lblElementOne" prefHeight="$xHeight" />
<Label fx:id="lblElementTwo" prefHeight="${xHeight * 2}" />
like image 95
Eng.Fouad Avatar answered Sep 30 '22 19:09

Eng.Fouad