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.javaLine 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 ...

Get Mastering JavaFX 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.