Button 带图像的按钮样式

Button 带图像的按钮样式,button,javafx-2,Button,Javafx 2,我想知道在JavaFx中,当文本位于图像下方时,如何实现以下按钮样式 我试了很多,但都没有成功。任何帮助都将不胜感激 键是contentDisplay属性,将其设置为“TOP” 使用fxml: <Button contentDisplay="TOP" layoutX="101.0" layoutY="51.0" mnemonicParsing="false" text="Button"> <graphic> <ImageView mouseTranspa

我想知道在JavaFx中,当文本位于图像下方时,如何实现以下按钮样式

我试了很多,但都没有成功。任何帮助都将不胜感激


键是
contentDisplay
属性,将其设置为“TOP”

使用fxml:

<Button contentDisplay="TOP" layoutX="101.0" layoutY="51.0" mnemonicParsing="false" text="Button">
  <graphic>
    <ImageView mouseTransparent="true" pickOnBounds="true" preserveRatio="true">
      <image>
        <Image url="@image.png" preserveRatio="false" smooth="false" />
      </image>
    </ImageView>
  </graphic>
</Button>

检查CSS参考。

您只需执行以下操作即可实现此目的

    Button b = new Button("text", graphics);
    b.setContentDisplay(ContentDisplay.TOP);

对于酷的图标,请看一看,其中包括来自和

抱歉,我无意中否决了。。。我发现取消否决票的唯一方法是让你先编辑你的帖子(只需添加一个点)。
    Button b = new Button("text", graphics);
    b.setContentDisplay(ContentDisplay.TOP);