Changing AWT line thickness

To change the line thickness from thin bands to thicker bands, like below:

line thickness

Set the “stroke” size used on the Graphics2D object:

   Graphics2D graphicsSG2D = ((Graphics2D) graphics);
   if(graphics instanceof Graphics2D) 
      stroke = graphicsSG2D.getStroke();
      graphicsSG2D.setStroke(new BasicStroke(3));

   if(graphics instanceof Graphics2D && stroke != null)

Don’t forget to save the previous stroke type, using


and then reset it after drawing this alternative-thickness line.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s