首页 > 解决方案 > 如何在 FXML 中直接在图像下方对齐文本?

问题描述

在 HTML5 中,我们可以使用 <figcaption>.

<figure>
  <img src="img.jpg" alt="my img"/>
  <figcaption> Your text </figcaption>
</figure>

现在我正在开发一个 JavaFX 应用程序,我想在每个图像的正下方点亮下一个。我主要有一个 for 循环来生成这些图像和文本。

在我有的 FXML

<HBox xmlns:fx="http://javafx.com/fxml" fx:controller="sample.AudioButtonController"  >
    <padding>
        <Insets topRightBottomLeft="30" />
    </padding>
    <children>
        <ImageView
                fitHeight="120" fitWidth="120" fx:id="image" onMousePressed="#mousePressed">
        </ImageView>
        <Text fx:id="text"/>
    </children>
</HBox>

文字显示在每张图片的前面。我想在每个图像下精确对齐 ehe 文本。

怎么做?

这就是它现在的样子:

申请图片

标签: javajavafxfxmljavafx-css

解决方案


推荐阅读