Okay, here's the deal. I'm having some trouble getting TextHitInfo to return
me valid data.

I have a TextLayout that I'm drawing centered within another component
using:

            textLayout.draw( g2d, (int)(bounds.getMinX() +
bounds.getWidth()/2 - stringWidth/2), (int)(bounds.getMinY() +
bounds.getHeight()/2 + stringHeight/2) );


Where bounds is the bounding box of the containing object. This works great.
The text is centered in my object.

Next I try to actually perform a hit test on the text by performing:

        Rectangle2D hitBounds = new Rectangle2D.Double(
textLayoutBounds.getMinX() + bounds.getMinX(),

textLayoutBounds.getMinY() + bounds.getMinY(),

textLayoutBounds.getWidth(),

textLayoutBounds.getHeight() );

        textHitInfo = textLayout.hitTestChar( x, y, hitBounds );

I create my own hitbounds because after confinued testing, the
textLayout.getBounds always remains at x=0, y=0 which is just wrong and is a
bug that I will report shortly. The bounds of the textLayout aren't at the
origin - they never are.

4508 [AWT-EventQueue-0] DEBUG PanelWidget  -
java.awt.geom.Rectangle2D$Float[x=0.0,y=0.0,w=56.0,h=8.0]
4510 [AWT-EventQueue-0] DEBUG PanelWidget  - x 223,161, bounds:
java.awt.geom.Rectangle2D$Double[x=171.0,y=132.0,w=56.0,h=8.0]
4511 [AWT-EventQueue-0] DEBUG PanelWidget  - Hit text - insert at = 8

Moving on. When I perform the hit test, I'm never getting the right
character insert position (hitInfo.getInsertionIndex()) unless the text is
sitting at the origin.


Any ideas?

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to