- Mastering JavaFX 10
- Sergey Grinev
- 123字
- 2021-06-25 21:21:57
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().
推薦閱讀
- Twilio Cookbook
- 物聯(lián)網(wǎng)之魂:物聯(lián)網(wǎng)協(xié)議與物聯(lián)網(wǎng)操作系統(tǒng)
- 局域網(wǎng)組建、管理與維護項目教程(Windows Server 2003)
- 智慧城市中的移動互聯(lián)網(wǎng)技術(shù)
- 通信簡史:從信鴿到6G+
- 網(wǎng)絡(luò)的琴弦:玩轉(zhuǎn)IP看監(jiān)控
- CCNP TSHOOT(642-832)認證考試指南
- Unity Artificial Intelligence Programming
- VMware NSX網(wǎng)絡(luò)虛擬化入門
- 6G無線網(wǎng)絡(luò)空口關(guān)鍵技術(shù)
- 物聯(lián)網(wǎng)頂層設(shè)計與關(guān)鍵技術(shù)
- Laravel Application Development Cookbook
- Hands-On Reactive Programming in Spring 5
- SEO攻略:搜索引擎優(yōu)化策略與實戰(zhàn)案例詳解
- 網(wǎng)絡(luò)分析技術(shù)揭秘:原理、實踐與WinPcap深入解析