How to draw strings around a circle

  • Follow


Hi,

I'm a Java newbie , and we got an assignment in school to program an
economic graph. The result is a circle devided in a variable number of
segments (standard : 12).

Everything is finished, the only problem is that I need to draw strings
around the circle. On the right hand side , no problem off course, but on
the left side, I would need to draw the string so that the end of the string
touches the circle.

Any suggestions on how to do this ?.

Regards ,

Oliver


0
Reply Flubbber 12/27/2003 4:17:12 PM

Flubbber wrote:

> [...] but on the left side, I would need to draw the string
 > so that the end of the string touches the circle.

You can measure the string's width for the
graphics context you render it on. This way
you can right-align it.

You can observe how I position strings in
my JDiskReport tool that you can find at:
http://www.jgoodies.com/freeware/jdiskreport/

Actually, the string positions in JDiskReport
are only the initial good guess. I could never
find the time to adjust them to better avoid
overlapping labels.

A true alternative is to render labels on both
sides and draw lines to the associated pies.

Hope this helps,
Karsten

0
Reply Karsten 12/27/2003 5:21:59 PM


> Everything is finished, the only problem is that I need to draw strings
> around the circle. On the right hand side , no problem off course, but on
> the left side, I would need to draw the string so that the end of the
string
> touches the circle.

you need to know width of your String.
Use FontMetrics.stringWidth(String);

____________

http://reader.imagero.com the best java image reader.


0
Reply ak 12/27/2003 9:22:23 PM

"Flubbber" <flubber476@hotmail.com> wrote in message
news:cgiHb.1002$eC4.139137302@hebe.telenet-ops.be...
...
> ...I need to draw strings
> around the circle. On the right hand side , no problem off course, but on
> the left side, I would need to draw the string so that the end of the
string
> touches the circle.

FontMetrics(Font f).stringWidth(String s);

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site


0
Reply Andrew 12/27/2003 11:21:16 PM

"Karsten Lentzsch" <Karsten@JGoodies.com> schreef in bericht
news:bskf3e$2jv$07$1@news.t-online.com...
> Flubbber wrote:
>
> > [...] but on the left side, I would need to draw the string
>  > so that the end of the string touches the circle.
>
> You can measure the string's width for the
> graphics context you render it on. This way
> you can right-align it.
>
> You can observe how I position strings in
> my JDiskReport tool that you can find at:
> http://www.jgoodies.com/freeware/jdiskreport/
>
> Actually, the string positions in JDiskReport
> are only the initial good guess. I could never
> find the time to adjust them to better avoid
> overlapping labels.
>
> A true alternative is to render labels on both
> sides and draw lines to the associated pies.
>
> Hope this helps,
> Karsten
>
>

Hi Karsten ,

How do you measure the width of the string ?
I know you can count the number of letters ,
but how do you know how much to draw ?

Oliver


0
Reply Flubbber 12/29/2003 5:47:58 PM

"Flubbber" <flubber476@hotmail.com> schreef in bericht
news:iNZHb.983$GI3.189788488@hestia.telenet-ops.be...
>
> "Karsten Lentzsch" <Karsten@JGoodies.com> schreef in bericht
> news:bskf3e$2jv$07$1@news.t-online.com...
> > Flubbber wrote:
> >
> > > [...] but on the left side, I would need to draw the string
> >  > so that the end of the string touches the circle.
> >
> > You can measure the string's width for the
> > graphics context you render it on. This way
> > you can right-align it.
> >
> > You can observe how I position strings in
> > my JDiskReport tool that you can find at:
> > http://www.jgoodies.com/freeware/jdiskreport/
> >
> > Actually, the string positions in JDiskReport
> > are only the initial good guess. I could never
> > find the time to adjust them to better avoid
> > overlapping labels.
> >
> > A true alternative is to render labels on both
> > sides and draw lines to the associated pies.
> >
> > Hope this helps,
> > Karsten
> >
> >
>
> Hi Karsten ,
>
> How do you measure the width of the string ?
> I know you can count the number of letters ,
> but how do you know how much to draw ?
>
> Oliver
>
>

    String s = xyList[i].getNaam();

   FontMetrics fm = getFontMetrics( g.getFont( ) );


   if ( xyList[i].getX() < 1 ){


    margex= fm.stringWidth( s );

   }

  the margex is the amount of pixels I move to te left, however , this
doesn't reallt work that good.

Oliver



0
Reply Flubbber 12/29/2003 6:27:49 PM

"Andrew Thompson" <andrew64@bigNOSPAMpond.com> schreef in bericht
news:MtoHb.67113$aT.18838@news-server.bigpond.net.au...
> "Flubbber" <flubber476@hotmail.com> wrote in message
> news:cgiHb.1002$eC4.139137302@hebe.telenet-ops.be...
> ..
> > ...I need to draw strings
> > around the circle. On the right hand side , no problem off course, but
on
> > the left side, I would need to draw the string so that the end of the
> string
> > touches the circle.
>
> FontMetrics(Font f).stringWidth(String s);
>
> --
> Andrew Thompson
> * http://www.PhySci.org/ PhySci software suite
> * http://www.1point1C.org/ 1.1C - Superluminal!
> * http://www.AThompson.info/andrew/ personal site
>
>
Hi Andrew ,

this is my code so far :

String s = xyList[i].getNaam();

   FontMetrics fm = getFontMetrics( g.getFont( ) );


   if ( xyList[i].getX() < 1 ){


    margex= fm.stringWidth( s );

   }


the margex is the amount of pixels I move to the left before drawing the
string, however this has a different result everytime I change the string.

the IF is used to see if the string is on the left of the circle.

Regards

Oliver




0
Reply Flubbber 12/29/2003 6:31:46 PM

Flubbber wrote:

> How do you measure the width of the string ?

I use FontMetrics#stringWidth(String).

Karsten

0
Reply Karsten 12/29/2003 7:31:34 PM

7 Replies
281 Views

(page loaded in 0.115 seconds)

Similiar Articles:













7/30/2012 6:52:31 AM


Reply: