if (!(g instanceof Graphics2D))
if (!(g instanceof Graphics2D) || true)
  public static void drawStringUnderlineCharAt(Graphics g, String text,                                               int underlinedIndex,                                               int x, int y)  {    Graphics2D g2;    Rectangle2D.Double underline;    FontRenderContext frc;    FontMetrics fmet;    LineMetrics lineMetrics;    Font font;    TextLayout layout;    double underlineX1, underlineX2;    boolean drawUnderline;    int textLength;    textLength = text.length();    if (textLength == 0)      return;    drawUnderline = (underlinedIndex >= 0) && (underlinedIndex < textLength);    if (!(g instanceof Graphics2D))    {      /* Fall-back. This is likely to produce garbage for any text       * containing right-to-left (Hebrew or Arabic) characters, even       * if the underlined character is left-to-right.       */      g.drawString(text, x, y);      if (drawUnderline)      {        fmet = g.getFontMetrics();        g.fillRect(          /* x */ x + fmet.stringWidth(text.substring(0, underlinedIndex)),          /* y */ y + fmet.getDescent() - 1,          /* width */ fmet.charWidth(text.charAt(underlinedIndex)),          /* height */ 1);      }      return;    }    g2 = (Graphics2D) g;    font = g2.getFont();    frc = g2.getFontRenderContext();    lineMetrics = font.getLineMetrics(text, frc);    layout = new TextLayout(text, font, frc);    /* Draw the text. */    layout.draw(g2, x, y);    if (!drawUnderline)      return;    underlineX1 = x + layout.getLogicalHighlightShape(     underlinedIndex, underlinedIndex).getBounds2D().getX();    underlineX2 = x + layout.getLogicalHighlightShape(     underlinedIndex + 1, underlinedIndex + 1).getBounds2D().getX();    underline = new Rectangle2D.Double();    if (underlineX1 < underlineX2)    {      underline.x = underlineX1;      underline.width = underlineX2 - underlineX1;    }    else    {      underline.x = underlineX2;      underline.width = underlineX1 - underlineX2;    }        underline.height = lineMetrics.getUnderlineThickness();    underline.y = lineMetrics.getUnderlineOffset();    if (underline.y == 0)    {      /* Some fonts do not specify an underline offset, although they       * actually should do so. In that case, the result of calling       * lineMetrics.getUnderlineOffset() will be zero. Since it would       * look very ugly if the underline was be positioned immediately       * below the baseline, we check for this and move the underline       * below the descent, as shown in the following ASCII picture:       *       *   #####       ##### #       *  #     #     #     #       *  #     #     #     #       *  #     #     #     #       *   #####       ######        ---- baseline (0)       *                    #       *                    #       * ------------------###----------- lineMetrics.getDescent()       */      underline.y = lineMetrics.getDescent();    }    underline.y += y;    g2.fill(underline);  }