Search code examples
javapaintcomponentgraphics2d

Smooth borders when drawing with setStroke


Hey I am currently working on a low level PaintProgram and I´m a little annoyed by the Rough lines iam drawing. When i set the stroke to 5 or higher of my Free Hand Drawing mode I get those edgy borders and it ends up looking rly bad:

Stroke 15, 20 and 50:

https://i.sstatic.net/gLOws.png

Sadly i can´t post pictures here... Am I able to create smooth borders easily?


Solution

  • Define your BasicStroke with something like:

    g2.setStroke(new BasicStroke(50, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));