I get the following error intermittenly when drawing a string with
graphics2d.drawString().

java.lang.IllegalArgumentException: Font
        at
sun.awt.font.NativeFontWrapper.drawStringShortDiscreteRaster(Native
Method)
        at
sun.java2d.loops.SCRDrawStringRasterContext.invoke(TextRendering.java:1576)
        at

sun.awt.image.BufferedImageGraphics2D.drawString(BufferedImageGraphics2D.java:1119)
        at
sun.java2d.pipe.ValidatePipe.drawString(ValidatePipe.java:124)
        at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2206)
        at

uchicago.src.sim.gui.SimGraphics.drawStringInHollowCircle(SimGraphics.java:219)
        ...

As you can see from the last line above, the code that causes this to
occur draws a hollow circle with a String in the center. To insure that
the String does not overflow the circle, I clip the graphics2D to
roughly the size of the circle. Anyway, here's the code.

  public void drawStringInHollowCircle(Color circleColor, Color
stringColor,
                                        String string)
  {
    drawHollowCircle(circleColor);
    Shape shape = g2.getClip();
    g2.setClip(curX, curY, curWidth, curHeight);

    drawInit(stringColor);
    FontRenderContext rContext = g2.getFontRenderContext();
    Rectangle2D bounds = g2.getFont().getStringBounds(string, rContext);

    int xCenter = curX + curWidth / 2;
    int yCenter = curY + curHeight / 2;

    int strX = xCenter - (int)bounds.getCenterX();
    int strY = yCenter - (int)bounds.getCenterY();

    g2.drawString(string, strX, strY);  <= exception thrown here.

    g2.setClip(shape);
  }

I'm not sure what to make of the error, and thus how to go about fixing
it.

thanks,

Nick
--

Nick Collier
[EMAIL PROTECTED]
Social Science Research Computing
University of Chicago
Chicago, IL 60637

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