【发布时间】:2012-08-21 09:52:26
【问题描述】:
我想知道是否有办法包含在同一个 FXML 文件中定义的代码(标签)。我想要的是多次包含相同的图像,而不必复制粘贴所有属性:
<HBox>
<Label translateY="25" alignment="center" text="">
<graphic>
<ImageView fitWidth="100" preserveRatio="true" smooth="true">
<image>
<Image url="arrow_right.png"/>
</image>
</ImageView>
</graphic>
</Label>
</HBox>
我想要类似的东西:
<fx:define>
<Label fx:id="myLabel" translateY="25" alignment="center" text="">
<graphic>
<ImageView fitWidth="100" preserveRatio="true" smooth="true">
<image>
<Image url="arrow_right.png"/>
</image>
</ImageView>
</graphic>
</Label>
</fx:define>
<HBox>
<fx:include source="$myLabel" />
</HBox>
我已阅读此答案https://stackoverflow.com/a/8490764/1606953,但它涵盖了包含外部源(=其他文件)。我对只包含一小段代码更感兴趣
谢谢大家
【问题讨论】: