JavaFx 2.x:如何绘制虚线或虚线? [英] JavaFx 2.x : How to draw dashed or dotted lines?
问题描述
我想从实线,点线或虚线动态更改线条的绘制:似乎我必须使用line.setStroke,这是正确的方法吗?
I would like to dynamically change the draw of a line from solid, dotted or dashed: it seems I have to use line.setStroke, is it the correct method?
那么,如何实现呢?
谢谢
推荐答案
不,这不是正确的方法,setStroke设置笔触的颜色.
正确的方法是getStrokeDashArray().add()
:
No that is not the correct method, setStroke sets the color of the stroke.
Correct method is 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定义线和间隙序列的模式.看到以下不同的模式作为上述内容的输出:
StrokeDashArray defines the pattern of line and gap sequences. See the following different patterns as output of aboves:
当然,通过操纵StrokeDashArray数组元素,您可以动态更改模式.
Of course by manipulating the StrokeDashArray array elements you can change the pattern dynamically.
这篇关于JavaFx 2.x:如何绘制虚线或虚线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!