I want to make the border of a borderpane more round and bold.
I tested this code:
bpi.setStyle("-fx-background-color: linear-gradient(to bottom, #f2f2f2, #d4d4d4);"
+ " -fx-border: 12px solid; -fx-border-color: white; -fx-background-radius: 15.0;"
+ " -fx-border-radius: 15.0");
I get this result:
How I can fix this?
Why your current approach doesn't work
Don't use
-fx-border
(it doesn't even currently exist in JavaFX CSS).Though there are other
fx-border-*
attributes such as-fx-border-color
,-fx-border-width
and-fx-border-radius
, I wouldn't recommend them either.Suggested Approach
Instead, use a combination of layered attributes:
-fx-background-color
-fx-background-insets
-fx-background-radius
You can find documentation on these CSS attribute features in the JavaFX CSS reference guide.
Although using
-fx-background-*
attributes for a border seems strange:-fx-border-*
attributes.Sample Code
For instance, here is an example fxml file which applies the standard modena.css style attribute values for "button like things" to a BorderPane. (modena.css comes from Java 8).
You can copy and paste the fxml and css, then load them up in SceneBuilder to see what it looks like.
button-like.css
button-like.fxml
Note
You wouldn't actually want to apply the above exact style in your application for styling something like a BorderPane, as that is not a "button like thing". Using the same styling for something that is not a button would confuse the user. But the sample approach should demonstrate the general idea on layering backgrounds to achieve the style you want.
Additional Example
This example uses the same FXML layout file defined above, just a different stylesheet to achieve a different style.