如何在Javafx中为XML文件创建常量变量 [英] How can I make constant variables in Javafx for XML files
本文介绍了如何在Javafx中为XML文件创建常量变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
StackPane layoutY =70.0
prefHeight =479.0
。我想在Java文件中创建值(70.0)
和(479.0)
static,以便我可以将它们用于其他文件。
StackPane layoutY="70.0"
prefHeight="479.0"
. I want to make the values (70.0)
and (479.0)
static in a Java file so I can use them for other files.
这可能吗?
推荐答案
James_D向您展示了使用自定义类来完成它。在fxml中执行此操作的另一种方法是定义自己的变量。但它们不能跨文件共享。
James_D showed you the way of doing it with a custom class. Another way of doing it in fxml is to define your own variables. But they are not shareable across files.
而不是这个
<StackPane layoutY="70.0" prefHeight="479.0">
你想拥有
<StackPane layoutY="$variable" prefHeight="$variable">
你可以这样做
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" id="AnchorPane" prefHeight="200" prefWidth="320" fx:controller="javafxapplication22.FXMLDocumentController">
<fx:define>
<Double fx:id="layoutY" fx:value="70.0"/>
<Double fx:id="prefHeight" fx:value="479.0"/>
</fx:define>
<children>
<StackPane layoutY="$layoutY" prefHeight="$prefHeight"/>
<Pane layoutY="$layoutY" prefHeight="$prefHeight"/>
</children>
</AnchorPane>
这篇关于如何在Javafx中为XML文件创建常量变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文