int lineWidth=3;
BasicStroke stroke=new BasicStroke((float)lineWidth);
g2D.setStroke(stroke);
The next step is, however, rather counter-intuitive. The line will be drawn half the pixels left from the coordinate that you specify.
int d=(int)((double)(lineWidth-1)/2.0);
The drawing command will draw line that fills the area (x0,y0) to (x1,y1).
g2D.drawLine(x0+d,y0+d,x1-(lineWidth-d),y1-(lineWidth-d));