关键是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>
Run Code Online (Sandbox Code Playgroud)
或CSS:
.your-selector {
-fx-content-display: top;
}
Run Code Online (Sandbox Code Playgroud)
在这里检查CSS参考.