I had a hard time following the answer in the link provided, so I give my solution which I think is a bit easier to understand. The problem is, if you scale a node the width of the stroke also scale's and you get these big fat lines for the shape. The solution that I use is that I apply a scaling transform to the node, and I also descale the width of the stroke. I'll
show the code for two different scenarios: 1.) I used an SVGPath node and show how to scale the svg without scaling the stroke line, and 2.) I'll do the same thing using the GraphicsContent on a canvas. Here's the code snippet
private void start() {
Task task = new Task<Void>() {
@Override
protected Void call() throws Exception {
double originalWidth, originalHeight, scaleX, scaleY;
// here's scaling using SVGPath Node type
SVGPath svgPath = new SVGPath();
svgPath.setFill(Color.TRANSPARENT);
//svgPath.setStrokeWidth(0);
svgPath.setStroke(Color.BLACK);
svgPath.setContent("M 0 0 L 6 0 L 6 5.5 A.5,.5 0 0 1 5.5 6 L0,6 L0,0");
// compute scale ratio
originalWidth = svgPath.prefWidth(-1);
originalHeight = svgPath.prefHeight(originalWidth);
scaleX = canvas1Width / originalWidth;
scaleY = canvas1Height / originalHeight;
// scale the svgPath; adjust the stroke width
svgPath.setScaleX(scaleX);
svgPath.setScaleY(scaleY);
svgPath.setStrokeWidth(1.0 / scaleX);
canvasGroup1.getChildren().addAll(svgPath);
// here's scaling using the Canvas / GraphicsContext
GraphicsContext gc = canvas2.getGraphicsContext2D();
double strokeWidth = gc.getLineWidth();
originalHeight =6;
originalWidth = 6;
scaleX = canvas2Width / originalWidth;
scaleY = canvas2Height / originalHeight;
Affine affine = new Affine();
affine.appendScale(scaleX, scaleY);
gc.setTransform(affine);
// the scaling must be set before the appendSVGPath statement
// the SVGPath will not scale if apply the transform after the appendSVGPath
gc.appendSVGPath("M 0 0 L 6 0 L 6 5.5 A.5,.5 0 0 1 5.5 6 L0,6 L0,0");
gc.setLineWidth(strokeWidth/scaleX);
gc.stroke();
Both scenarios work, but I will mention that there are two cons to using the GraphicsContext approach. First, the GraphicsContext approach doesn't produce as smooth of an arc as using the SVGPath. Lines are fine. Secondly, you can't easily get the bounds of the appendSVGPath to compute your scaling factor. As you may notice, I hard wired them in for that scenario.