469,931 Members | 1,831 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,931 developers. It's quick & easy.

How to set a thickness to a line being drawn?

blazedaces
284 100+
Hey, I have an application that draws a polyline with Graphics':

Expand|Select|Wrap|Line Numbers
  1. g.drawPolyline(getXPoints(),getYPoints(),nPoints);
It's drawn onto a background image and so the background image is so many pixels wide (the line I'm trying to "copy" or draw), but this drawn polyline is very thin, probably 1 pixel wide. Any way to change the thickness of a drawn line like this? Like another class? I've looked at graphics2D and I see no extra possibility there.

The only thing I can cook up is trying to manually either draw multiple polylines by drawing multiple points around it to "hack" thickness of a single line, don't know exactly how I would do that yet though.

Thought maybe there's something simple out there like a way to set a composite of graphics2D and somehow there is a line width I don't know. I didn't see anything like that, but maybe you guys know...

If you guys have other ideas on how to "hack" a thicker line too, would be appreciated.

Btw, background: I have a picture of a graph and instead of reading points from it one by one I wrote a program which draws some circles (its a polar graph) and I measured the pixels so it matches up great. It's intended that after I "draw" on top of the pictured graph, I'll have the points stored and can then write them to a file (that will do something else, but I'm not there yet).

That's why I want a thicker line, because I want it to draw over the line that's in the graph's picture. Mostly it's for visibility reasons though, so I can see I've drawn it correctly. Also, is orange the best color for visibility on top of let's say black or green or white? I thought it would stick out...

Thanks for any and all help/information.

-blazed
Jun 8 '07 #1
2 7346
JosAH
11,448 Expert 8TB
That Graphics object passed in to your drawComponent method is actually
a Graphics2D methods (you can cast the first to the second). The second class
implements a method setStroke(Stroke stroke). The Stroke object determines
how things should be drawn. Also have a look at the BasicStroke class.

kind regards,

Jos
Jun 8 '07 #2
blazedaces
284 100+
That Graphics object passed in to your drawComponent method is actually
a Graphics2D methods (you can cast the first to the second). The second class
implements a method setStroke(Stroke stroke). The Stroke object determines
how things should be drawn. Also have a look at the BasicStroke class.

kind regards,

Jos
Thanks a bunch dude.

-blazed
Jun 8 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by MikeY | last post: by
reply views Thread by alexandre_irrthum | last post: by
1 post views Thread by alexandre_irrthum | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.