【问题标题】:Button style with image带图像的按钮样式
【发布时间】:2013-12-18 00:51:29
【问题描述】:

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

我尝试了很多,但都是徒劳的。任何帮助将不胜感激。

【问题讨论】:

    标签: button javafx-2


    【解决方案1】:

    关键是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:

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

    检查 CSS 参考 here

    【讨论】:

      【解决方案2】:

      您只需这样做就可以实现这一目标

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

      对于很酷的图标,看看http://fxexperience.com/controlsfx/features/ 它包括来自FontAwesomeIcoMoon 的图标

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-08
      • 1970-01-01
      • 1970-01-01
      • 2012-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多