Why Is "-Fx-Background-Radius: 10;" Not Working

Border-radius in JavaFX CSS not working on containers

Do not use borders. Css background instead.
Load the sample to SceneBuilder to get the idea.

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.layout.StackPane?>

<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: silver;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="300.0" style="-fx-background-color: purple, blue; -fx-background-radius: 8, 0; -fx-background-insets: 0, 4;">
<effect>
<DropShadow />
</effect>
</StackPane>
</children>
</StackPane>

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

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 bachground will be drawn as a non-rounded rectangle.

JavaFX - Border radius - Background color

You need to add the radius property as well to define the background fill. Otherwise it will asume a zero value, as shown in your picture.

You can check the CSS specs here.

You just need to add the -fx-background-radius property:

.payload {
-fx-hgap: 20px;
-fx-padding: 40px;

-fx-background-color: #2969c0;
-fx-background-radius: 50px;

-fx-border-radius: 50px;
-fx-border-width: 5px;
-fx-border-color: black;
-fx-effect: dropshadow(three-pass-box, rgba(0, 0, 0, 0.8), 10, 0, 0, 0);
}

background radius



Related Topics



Leave a reply



Submit