2016-05-01 24 views
1

我使用按鈕在javafx中製作隨機圖像庫。我將imageView設置爲按鈕,因爲我需要點擊圖片。問題是imageView未按預期在按鈕上設置。按鈕具有PREF的高度和寬度爲110爲什麼按鈕上的javafx圖像查看未按預期設置

This is the Before Image note Buttons distance

This is after Image why distance is changed

下面是代碼正在使用來設置按鈕ImageView的。

for(int i=0; i<35; i++){ 
    Button button = list.get(i); 
    ImageView imageview =new ImageView(imageList.get(i)); 
    imageview.setPreserveRatio(true); 
    imageview.setFitHeight(110); 
    imageview.setFitWidth(110); 
    button.setGraphic(imageview); 
} 
+0

我不明白的問題。你想填充(圖像周圍的灰色區域)不在那裏嗎? – ItachiUchiha

+0

在添加imagview之後和之前,您可以看到按鈕之間的空間。我不希望像第二張圖片那樣改變空間。 –

回答

1

您需要將Button S的padding更改爲空:

Button button = new Button(null, imageView); 

// quadratic grey background 
button.setBackground(new Background(new BackgroundFill(Color.GREY, CornerRadii.EMPTY, Insets.EMPTY))); 

// no padding 
button.setPadding(Insets.EMPTY);