我正在尝试弄清楚是否可以为具有自定义形状的节点绘制边框。目前,边框不适合节点的形状。
目前它看起来像这样:
该形状是通过以下CSS实现的:
这是箭头类的重要代码,其中使用了CSS:
Arrow类是一个HBox,其中我创建了一个自定义形状的区域作为箭头尾部和箭头头部,另一个包含标签的HBox作为箭头中间部分。
目前它看起来像这样:
![enter image description here](https://istack.dev59.com/ozQCH.webp)
.arrow-tail {
-fx-shape: "M 0 0 L 10 0 L 10 10 L 0 10 L 10 5 Z";
}
.arrow-head {
-fx-shape: "M 0 0 L 10 5 L 0 10 Z";
}
这是箭头类的重要代码,其中使用了CSS:
public class Arrow extends HBox {
public void Arrow(Node graphic, String title) {
getChildren().addAll(getArrowTail(), getArrowMiddlePart(graphic, title), getArrowHead());
}
private final Region getArrowTail() {
final Region arrowTail = new Region();
arrowTail.setMinWidth(10);
arrowTail.getStyleClass().add("arrow-tail");
return arrowTail;
}
private final Node getArrowMiddlePart(Node graphic, String text) {
labelTitle = new Label(text);
labelTitle.setGraphic(graphic);
labelTitle.idProperty().bind(idProperty());
final Tooltip tooltip = new Tooltip();
tooltip.textProperty().bind(labelTitle.textProperty());
Tooltip.install(labelTitle, tooltip);
final HBox arrowMiddlePart = new HBox(labelTitle);
arrowMiddlePart.minWidthProperty().bind(minWidthProperty());
arrowMiddlePart.setAlignment(Pos.CENTER);
return arrowMiddlePart;
}
private final Region getArrowHead() {
final Region arrowHead = new Region();
arrowHead.setMinWidth(10);
arrowHead.getStyleClass().add("arrow-head");
return arrowHead;
}
}
Arrow类是一个HBox,其中我创建了一个自定义形状的区域作为箭头尾部和箭头头部,另一个包含标签的HBox作为箭头中间部分。