我想创建类似于预先定义的“虚线”样式(-fx-border-style: dashed
)的边框样式。
如何在CSS中使用虚线段,线帽和线连接的自定义长度创建虚线边框?
见JavaFX的CSS参考Region
,特别是对于可能的值-fx-border-style
。您可以使用segments(...)
定义任意线段长度:还有用于设置line-cap
(square
,butt
,或round
)和line-join
(miter
,bevel
或round
)。
快速示例:
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);
}
}
与
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 ;
}
这使
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句