Much thanks to Doug Felt at Sun for helping me out with thist! Man
this was driving me nuts. Doug I own you one of whatever drink you
want whenever I see you - I'm serious! This area of code was driving
me INSANE. I couldn't take it anymore :)

Anyways, what I had to do was take the x, y where the hit was taking
place and subtract the (x,y) that is the origin of the TextLayout that
I want to check against. The TextLayout hit testing does NOT take
place in the same coordinate space as screen space. Yeah, confused the
hell out of me too. It would be nice if there was just an additional
method that took the screen space coordinate and gave back the right
thing since most people will be clearly performing the check in screen
space. Anyways, my changed code looks like

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

    public void onClick( int x, int y )
    {
        textHitInfo = textLayout.hitTestChar( x -fontX, y -fontY );

        if ( textHitInfo != null )
        {
            logger.debug("Hit text - insert at = " +
textHitInfo.getInsertionIndex() );
        }
    }

Note that the bounds that I was previously using is completely
unnecessary and used by Java2D/TextLayout for something entirely
different.

===========================================================================
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