Jovan Dukic
Jovan Dukic

Reputation: 69

How to make image fill entire button JavaFX

I want to make image to fit entire button with no extra space. I have tried this, but its not working:

 .toggle-button {
 -fx-background-image: url("close.png");
 -fx-background-repeat: stretch;
 -fx-background-position: center center;
}

 .toggle-button:selected{
 -fx-background-image: url("contact.png");
}

This is the result I get:

enter image description here

How to make that exit picture (red square) fill entire button?

Upvotes: 3

Views: 1296

Answers (1)

Zeusox
Zeusox

Reputation: 8468

You need to set the background-size, otherwise the background size is set to zero. Try the following:

.toggle-button  {

    -fx-min-height: 132px;

    -fx-min-width: 128px;

    -fx-background-image: url("close.png");

    -fx-background-size: 100% 100%;

    -fx-background-repeat: no-repeat;

    -fx-background-position: center 8px;

}

Upvotes: 4

Related Questions