【发布时间】:2019-10-27 15:47:12
【问题描述】:
我想使用 FXML 包含带有图标和文本的按钮。
我知道在 FXML 中我可以使用以下代码添加图像:
<ImageView id="boxImage" fitWidth="100" fitHeight="100">
<image>
<Image url="@/com/example/app/resources/icons/office.png" />
</image>
</ImageView>
但我想知道如何将其与按钮代码合并:
<Button text="DATE"/>
非常欢迎任何帮助或示例,因为我完全不知道如何使用 FXML 应用图像。
编辑
我的回答如下:
<Button text="INSTRUMENT" styleClass="">
<graphic>
<ImageView pickOnBounds="true" preserveRatio="true">
<image>
<Image url="/com/example/app/resources/icons/instrument.png" />
</image>
</ImageView>
</graphic>
</Button>
但我明白了:
按钮增加了它的高度,因此不再与其他没有图像的按钮对齐。
【问题讨论】:
-
子项的对齐/调整大小是布局的任务 - 选择适合您要求的布局。顺便说一句,你展示了你不想要的东西,最好是解释你想要想要实现的目标,最好是minimal reproducible example