2016-11-30 117 views
0

我正試圖完成兩個目標。FXML圖像透明度

  1. 讓圖像對文本透明。
  2. 沒有圖像擠壓文本的權利。

    <Button fx:id="btn" layoutX="90.0" layoutY="14.0" mnemonicParsing="false" prefHeight="97.0" prefWidth="320.0" styleClass="root" text="Button"> 
        <graphic> 
         <ImageView fitHeight="87.0" fitWidth="244.0"> 
          <image> 
           <Image url="@image.jpg"/> 
          </image> 
         </ImageView> 
        </graphic> 
    </Button> 
    

任何幫助是極大的讚賞。

+0

http://stackoverflow.com/questions/16340269/styling-a-javafx-2-button-using-fxml-only-how - 添加一個圖像到一個按鈕 – FamousFrik

+0

http://stackoverflow.com/questions/34852751/button-with-image-styling-with-fxml-css – FamousFrik

回答

0

the contentDisplay property設置爲ContentDisplay.CENTER。這應該繪製文本上與Button使用的graphic的頂部:

<Button fx:id="btn" contentDisplay="CENTER" ...> 
    ... 
</Button> 
+0

這個工作,但無論如何淡出圖像使用fxml? – FamousFrik

+0

@FamousFrik淡出像設置不透明度或使用適當的'ColorAdjust'效果??? – fabian

+0

這是一個很好的工作點和部分答案。有沒有辦法將圖像繪製到背面,而不必將文本移動到本示例的中心?因此,圖像回到左側,文字在中心或右側? – FamousFrik

0

你可以做的是讓舞臺上的透明,這樣就可以了,一切都會使用這種方法是透明的:stage.initStyle(StageStyle.TRANSPARENT)然後,你可以設置現場透明以及scene.setFill(Color.TRANSPARENT).批准這個答案,如果這個解決您的問題:)

+0

謝謝,但我用場景生成器,所以我試圖保持FXML中的代碼。試過這個無濟於事。感謝您的輸入。 – FamousFrik

+0

那麼你只是想讓圖像成爲應用程序的背景? – Aaron

+0

後面的文字,但不一定整個背景如果有意義 – FamousFrik