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

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.java
hbox.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);

hbox.getChildren().add(new VBox(5, new Text(type.toString()), rect));
}

We get the following output:

Some shapes may have no inner area at all, for example, Line. So, to change the color of such a shape you need to use setStroke() rather than setFill().

主站蜘蛛池模板: 莱芜市| 长沙市| 金堂县| 滨州市| 莱州市| 永丰县| 西乌珠穆沁旗| 财经| 贺兰县| 水富县| 即墨市| 陇川县| 云梦县| 红桥区| 威远县| 莱西市| 镇巴县| 沙坪坝区| 太仓市| 石泉县| 冷水江市| SHOW| 庄浪县| 密山市| 江门市| 女性| 九台市| 崇明县| 安丘市| 石狮市| 太康县| 南充市| 台江县| 太原市| 杨浦区| 镇原县| 迁安市| 于田县| 阿克陶县| 河西区| 文山县|