I have a GeneralPath that I draw with two different BasicStrokes.
The two strokes are (intended to be) identical except that one is
dashed.

What I'm observing is that in some cases the two stroked outlines
do not overlap, as I'd expect them to.  Are my expectations incorrect?

I'm including a simple program that demonstrates the problem.

You can find a (blown up) screen capture here:

    http://cradle.brokenglass.com/images/dash.png

This is occurring with (at least) the following:

  Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
  Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)

Thanks in advance.

-David


----

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;



public class DashTest extends JFrame {

    class BoxCanvas extends JPanel {

        Stroke      dashStroke_;
        Stroke      lineStroke_;
        Shape       shape_;


        BoxCanvas() {

            BasicStroke ds = new BasicStroke();

            lineStroke_ = ds;
            dashStroke_ = new BasicStroke(
                ds.getLineWidth(), ds.getEndCap(), ds.getLineJoin(),
                ds.getMiterLimit() , new float[] {8, 8}, 0
            );

            shape_ = makeShape();

            setBackground( new Color( 0, 200, 0));
            setPreferredSize( new Dimension(100, 100));
        }



        private Shape
        makeShape() {

            GeneralPath p = new GeneralPath();

            p.moveTo( 20.0f, 70.0f );
            p.lineTo( 70.9f, 70.0f);
            p.lineTo( 70.9f, 20.0f);
            p.lineTo( 20.0f, 20.0f );
            p.closePath();

            return p;
        }



        public void
        paintComponent( Graphics g ) {
            super.paintComponent( g );
            Graphics2D g2 = (Graphics2D) g;

            g2.setStroke( lineStroke_ );
            g2.setColor( Color.BLACK );
            g2.draw( shape_ );

            g2.setStroke( dashStroke_ );
            g2.setColor( Color.WHITE );
            g2.draw( shape_ );
        }
    }



    public DashTest() {
        super( "DashTest" );

        JPanel canvas = new BoxCanvas();
        getContentPane().add( canvas );
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    }



    public static void
    main( String[] args ) {

        DashTest app = new DashTest();
        app.pack();
        app.setVisible( true );
    }
}





------------------------+--------------------------+
David Eisner            | E-mail: [EMAIL PROTECTED]   |
CALCE EPSC              | Phone:  301-405-5341     |
University of Maryland  | Fax:    301-314-9269     |
------------------------+--------------------------+

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to