| Author |
Drawing a GeneralPath using a dashed stroke
|
Peter Kolb
Greenhorn
Joined: Nov 19, 2008
Posts: 8
|
|
Hi all,
I have recently started to support dashed strokes in my application and found that dashed strokes are not well suited for drawing GeneralPaths. The unstroked segments are too small, and at one point they disappear, making the dashed GeneralPath look like a solid GeneralPath.
Here is some sample code to play:
The line and the rectangle are drawn correctly with a dashed stroke, but the Path2D.Double is a continuous line.
Can anybody reproduce it, and can this be solved?
This code was tested on WinMe and WinXP, java build 1.6.0_22-b04.
Thanks for help,
Peter
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
|
Aren't you supposed to set the Stroke before you draw the GeneralPath?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
|
No, that isn't the problem. I shall try something different.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
|
What you are doing is drawing a line down to the right, then when you close the path, you are coming back. So all your dashes are overwriting the gaps. Try changing the first lineTo to read lineTo(401, 301), then you aren't drawing a double line, and it should work for you.
|
 |
Peter Kolb
Greenhorn
Joined: Nov 19, 2008
Posts: 8
|
|
Thanks a lot, that did it!
However, some real-world cases are still misbehaved. I probably need to look more careful at the construction of the corresponding GeneralPaths.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
You're welcome
|
 |
 |
|
|
subject: Drawing a GeneralPath using a dashed stroke
|
|
|