The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.awt  [78 examples] > Drawing  [7 examples]

e579. Changing the Thickness of the Stroking Pen

dashPhase is the offset to start the dashing pattern.
    // See e575 The Quintessential Drawing Program
    public void paint(Graphics g) {
        Graphics2D g2d = (Graphics2D)g;
        float strokeThickness = 5.0f;
    
        // A solid stroke
        BasicStroke stroke = new BasicStroke(strokeThickness);
        g2d.setStroke(stroke);
        // Draw shapes...; see e586 Drawing Simple 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...; see e586 Drawing Simple Shapes
    }

 Related Examples
e575. The Quintessential Drawing Program
e576. Drawing with Alpha
e577. Enabling Antialiasing
e578. Setting the Clipping Area with a Shape
e580. Stroking or Filling with a Texture
e581. Animating an Array of Images in an Application

See also: Colors    Components    Containers    Cursors    Events    Focus    Frames    GridBagLayout    Images    Shapes    Simulating Events    Text    The Screen   


© 2002 Addison-Wesley.