Basic Stroke

Note that the JavaFX developers decided to not introduce an extra class for strokes; all corresponding methods belong to the Shape class instead:

shape.setStroke(Color.BLACK);shape.setStrokeWidth(10);shape.setStrokeType(StrokeType.CENTERED);

The first two are pretty self-explanatory—color and width. Next up is a stroke type that controls positioning relative to shape's edge. See the following image and corresponding sample:

// chapter2/strokes/StrokeTypesDemo.javahbox.getChildren().add(new VBox(5, new Text("NONE"), new Rectangle(50,50, Color.LIGHTGRAY)));for (StrokeType type : StrokeType.values()) {    Rectangle rect = new Rectangle(50,50, Color.LIGHTGRAY);    rect.setStrokeType(type);    rect.setStroke(Color.BLACK); rect.setStrokeWidth(10); ...

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.