I would like to create border style similar to predifened "dashed" style
(-fx-border-style: dashed
).
How to create dashed border in CSS with custom lengths of dash segments, line cap and line join?
See the JavaFX CSS reference for Region
, in particular the possible values for -fx-border-style
. You can use segments(...)
to define arbitrary line segment lengths: there are also settings for line-cap
(square
, butt
, or round
) and line-join
(miter
, bevel
, or round
).
Quick example:
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class CustomBorderExample extends Application {
@Override
public void start(Stage primaryStage) {
Region region = new Region();
region.getStyleClass().add("custom-dashed-border");
region.setMinSize(400, 400);
StackPane root = new StackPane(region);
root.setPadding(new Insets(16));
Scene scene = new Scene(root, 480, 480);
scene.getStylesheets().add("custom-dashed-border.css");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
with
custom-dashed-border.css:
.custom-dashed-border {
-fx-border-color: blue ;
-fx-border-width: 5 ;
-fx-border-style: segments(10, 15, 15, 15) line-cap round ;
}
which gives
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With