gpt4 book ai didi

line - JavaFX 2.x : How to draw dashed or dotted lines?

转载 作者:行者123 更新时间:2023-12-03 04:26:47 28 4
gpt4 key购买 nike

我想动态更改实线、点线或虚线的绘制:看来我必须使用 line.setStroke,这是正确的方法吗?

那么,如何实现这一点?

谢谢

最佳答案

不,这不是正确的方法,setStroke 设置笔画的颜色。
正确的方法是getStrokeDashArray().add():

Line line1 = new Line(20, 40, 270, 40);
line1.getStrokeDashArray().addAll(25d, 20d, 5d, 20d);

Line line2 = new Line(20, 60, 270, 60);
line2.getStrokeDashArray().addAll(50d, 40d);

Line line3 = new Line(20, 80, 270, 80);
line3.getStrokeDashArray().addAll(25d, 10d);

Line line4 = new Line(20, 100, 270, 100);
line4.getStrokeDashArray().addAll(2d);

Line line5 = new Line(20, 120, 270, 120);
line5.getStrokeDashArray().addAll(2d, 21d);

pane.getChildren().addAll(line1, line2, line3, line4, line5);

StrokeDashArray 定义线条和间隙序列的模式。请参阅以下不同模式作为上述输出:

enter image description here

当然,通过操作 StrokeDashArray 数组元素,您可以动态更改模式。

关于line - JavaFX 2.x : How to draw dashed or dotted lines?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12786363/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com