Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2003

Tip: Looking for answers? Try searching our database.

How to draw strings around a circle

Thread view: 
Flubbber - 27 Dec 2003 16:17 GMT
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
Karsten Lentzsch - 27 Dec 2003 17:21 GMT
> [...] 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
Flubbber - 29 Dec 2003 17:47 GMT
> > [...] but on the left side, I would need to draw the string
>  > so that the end of the string touches the circle.
[quoted text clipped - 17 lines]
> 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
Flubbber - 29 Dec 2003 18:27 GMT
> > > [...] but on the left side, I would need to draw the string
> >  > so that the end of the string touches the circle.
[quoted text clipped - 25 lines]
>
> 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
Karsten Lentzsch - 29 Dec 2003 19:31 GMT
> How do you measure the width of the string ?

I use FontMetrics#stringWidth(String).

Karsten
ak - 27 Dec 2003 21:22 GMT
> 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.
Andrew Thompson - 27 Dec 2003 23:21 GMT
..
> ...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
Flubbber - 29 Dec 2003 18:31 GMT
> ..
> > ...I need to draw strings
[quoted text clipped - 10 lines]
> * 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.