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: draw rectangles - comp.soft-sys.matlabHow to create points in a rectangle/circle using normal ... How to draw strings around a circle - comp.lang.java.gui ... How to create points in a rectangle/circle using ... Draw Circle in matrix - comp.soft-sys.matlabHow do yo draw a circle in a matrix with the value at 10V?? This ... it's a rectangle or maybe some scattered elements around the matrix), what does it mean to put a circle ... How to create points in a rectangle/circle using normal ...Hello, I wanted to create points around the center of circle more and when density of points goes low as it approaches the circumference. Same I wa... plotting circles in matlab - comp.soft-sys.matlabNow, i'd like to plot a circle around each point of the trajectory; and the diameter ... how to draw a circle inside circle - comp.soft-sys.matlab ... Function to plot circle ... how to draw an arc between two points given centre and radius ...how to draw an arc between ... routine intended to draw an arc from a start point to an end point around a ... Arc of a circle - comp.lang.idl-pvwave how to draw an arc between ... How to draw the 'tau' symbol - comp.lang.idl-pvwavetau=!4+STRING("163B)+!X David fannig has a great article explaining that ... comp.graphics.api.opengl Hi all, A very basic question I guess : how do I draw a circle ... Draw a Cone - comp.graphics.api.openglI have looked through the book and cannot quite get my head to wrap around how to draw ... are two ways to draw a cone. Cylinder Method Use the Circle tool to draw a circle ... How to make an Helix over a 3D spline - comp.cad.solidworks ...our SolidSketch add-in can wrap any sketch around any surface (see www.solidplus ... draw a circle for the helix diameter and then use the helix tool as appropriate to make ... Including an area into a circle - comp.soft-sys.matlabHi, I tried to draw a circle on top of my current figure, so I can see ... Here's a circle drawing demo I have lying around. See if you can adapt it to draw what you want. Cutting hole through tube - comp.cad.solidworksyou can do it the way you are but it's the long way around for what you've ... When I start my sketch, I select a plane, and the circle I draw > happens to fall right ... How to Draw a Circle | eHow.comLearn to draw a circle using string and a pencil. To do this, tie a piece of string around a pencil (near the pencil point). Hold the string with one hand straight ... How to Draw a Circle With String | eHow.comHow to Draw a Circle. Learn to draw a circle using string and a pencil. To do this, tie a piece of string around a pencil (near... How to Make a String Puppet 7/30/2012 6:52:31 AM
|