2013-12-17 91 views
0

我想知道如何實現以下按鈕樣式,其中文本位於JavaFx中的圖像下方?帶圖像的按鈕樣式

我嘗試了很多,但都徒勞無功。任何幫助,將不勝感激。

enter image description here

回答

4

的關鍵是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/它包括從ICONE和FontAwesomeIcoMoon

+0

對不起,我不小心downvoted ...唯一的辦法我發現取消downvote是讓你先編輯你的帖子(只需添加一個點)。 http://meta.stackexchange.com/questions/139949/unable-to-undo-downvote –