是否可以在FXML中使用算术表达式? [英] Is it possible to use arithmetic expression in FXML?

查看:159
本文介绍了是否可以在FXML中使用算术表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有一个功能可以让我在FXML中使用数字。例如,尝试将一个元素的高度定义为等于常量,将第二个元素的高度定义为等于相同的常量* 2。是否有可能在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*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 controler (which I would like to avoid)?

推荐答案

是的,有可能:

<?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}" />

这篇关于是否可以在FXML中使用算术表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆