Java Graphics Draw Lines

Java Graphics Draw Lines

Drawing Thicker Lines

There is no predefined method to draw a thicker line in Java. Drawing lines with a gap of one pixel makes a thicker line. One pixel is the minimum distance that can be measured on the screen.

The following program draws 4 pixel thick horizontal line.

Java Graphics Draw Lines
Output of of Java Graphics Draw Lines

g.drawLine(40, 50, 250, 50);
g.drawLine(40, 51, 250, 51);

Keeping y1 and y2 coordinates same draws a horizontal line; other way, it is vertical when x1 and x2 are same. Observe, y1 and y2 are moved down by one pixel. The next line is drawn just below the previous line.

Leave a Reply

Your email address will not be published. Required fields are marked *