Alireza
Alireza

Reputation: 43

-fx-background-radius and -fx-background-insets in JavaFX

I am working with JavaFX and I want to customize a button. I saw several characteristics that can be styled. Among them I found two that are unknown to me.

.button {
    -fx-padding: 5 22 5 22;   
    -fx-border-color: #121212;
    -fx-border-width: 2;
    -fx-border-radius: 5;
    -fx-background-radius: 0;
    -fx-background-color: #555555;
    -fx-font-family: "Segoe UI", Helvetica, Arial, sans-serif;
    -fx-font-size: 11pt;
    -fx-text-fill: #d8d8d8;
    -fx-background-insets: 0 0 0 0, 0, 1, 2;
}

what are these two properties:

-fx-background-insets: 0 0 0 0, 0, 1, 2; 

and

 -fx-background-radius: 0;

I saw this, but it is very vague for me.

Upvotes: 3

Views: 22906

Answers (1)

fabian
fabian

Reputation: 82491

These 2 properties are documented in the linked document, but I'd prefer using the latest version: JavaFX CSS Reference: Region

Those 2 properties are used to create the background of the Button; they are used as the constuctor parameters for the BackgroundFill constructors (4 BackgroundFills will be used for the background since 0 0 0 0, 0, 1, 2 contains 4 sets of insets).

-fx-background-insets

This specifies the distance from the Button's bounds where the background should be drawn. E.g. if you have a button positioned at x=50, y=150, width=200, height=100 and use insets 10 20 30 40 the region used for the background is x=50+40=90, y=150+10=160, width=200-20-40=140, height=100-10-30=60.

-fx-background-radius

The background is drawn as a rounded rectangle. This is the radius of the corners. In this case 0 means the background will be drawn as a non-rounded rectangle.

Upvotes: 8

Related Questions