Forums Register Login

Drawing a GeneralPath using a dashed stroke

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Aren't you supposed to set the Stroke before you draw the GeneralPath?
+Pie Number of slices to send: Send
No, that isn't the problem. I shall try something different.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
You're welcome
His brain is the size of a cherry pit! About the size of this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3275 times.
Similar Threads
Turning images around the clock
AffineTransform "transform" method
Making a diagram interactive???
A flatland puzzle
percentage based background scheme for a JPanel
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:46:02.