10.6. Stroke Styles

In the AWT, the drawXxx methods of Graphics resulted in solid, 1-pixel-wide lines. Furthermore, drawing commands that consisted of multiple-line segments (e.g., drawRect and drawPolygon) had a predefined way of joining the line segments and terminating segments that did not join to others. Java 2D gives you much more flexibility. In addition to setting the pen color or pattern (through setPaint, as discussed in the previous section), with Java 2D you can set the pen thickness and dashing pattern and specify the way in which line segments end and are joined together. To control how lines are drawn, first create a BasicStroke object, then use the setStroke method to tell the Graphics2D object to use the BasicStroke object.

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.