Button style with image

后端 未结 2 1423
被撕碎了的回忆
被撕碎了的回忆 2021-01-26 15:19

I was wondering How one can achieve following button style where text resides underneath of image in JavaFx?

I tried a lot but all in vain. Any help would be appreciate

相关标签:
2条回答
  • 2021-01-26 15:58

    The key is the contentDisplay property, set it to "TOP".

    With 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>
    

    Or CSS:

    .your-selector {
        -fx-content-display: top;
    }
    

    Check the CSS reference here.

    0 讨论(0)
  • 2021-01-26 16:14

    You can simply achieve that just by doing

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

    And for cool icons, take a look at http://fxexperience.com/controlsfx/features/ it include icone from FontAwesome and IcoMoon

    0 讨论(0)
提交回复
热议问题