官术网_书友最值得收藏!

Dashed lines

By using the strokeDashArray method, you can make dashed lines. Each dash's size, and the spaces between them, are set in Stroke Dash Array. Each odd position is the dash length, and each even position is the length of the space before the next dash. Refer to the following code snippet:

// chapter2/strokes/DashExamples.java
Line line = new Line(50, 0, 250, 0);
line.setStrokeWidth(10);
line.setStroke(Color.DARKGRAY);
line.getStrokeDashArray().addAll(30.0, 15.0);

This method will give us the following line:

Note that the gaps between dashes look smaller than the 15 pixels we set. This is because, by default, StrokeLineCap is set to SQUARE, which means each gap ends with half of a square shape with a size of the half of stroke width. Here is a comparison of all three line caps:

And the last thing to note about dash is offset, which is a point in the dashed line that will be used as a start for drawing it:

line.setStrokeDashOffset(20);
主站蜘蛛池模板: 嘉鱼县| 四川省| 九龙县| 禹州市| 永宁县| 临洮县| 紫金县| 怀宁县| 文水县| 贡嘎县| 武宣县| 东莞市| 贡觉县| 锡林郭勒盟| 盐边县| 双鸭山市| 石景山区| 吉林省| 军事| 改则县| 三台县| 卢龙县| 田东县| 乾安县| 安乡县| 剑川县| 张家口市| 锡林浩特市| 梁平县| 汉中市| 安多县| 加查县| 海安县| 裕民县| 巴中市| 蚌埠市| 昌图县| 合山市| 霍邱县| 即墨市| 瓦房店市|