Changing the Thickness of the Stroking Pen - Java 2D Graphics

Java examples for 2D Graphics:Paint

Description

Changing the Thickness of the Stroking Pen

Demo Code

import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;

public class Main {
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    float strokeThickness = 5.0f;

    // A solid stroke
    BasicStroke stroke = new BasicStroke(strokeThickness);
    g2d.setStroke(stroke);/*from  www  . java2  s . c  om*/
    // Draw shapes...;

    // A dashed stroke
    float miterLimit = 10f;
    float[] dashPattern = { 10f };
    float dashPhase = 5f;
    stroke = new BasicStroke(strokeThickness, BasicStroke.CAP_BUTT,
        BasicStroke.JOIN_MITER, miterLimit, dashPattern, dashPhase);
    g2d.setStroke(stroke);
    // Draw shapes...;
  }
}

Related Tutorials