Here you can find the source of drawUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y)
public static void drawUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y)
//package com.java2s; //License from project: Apache License import java.awt.*; public class Main { public static void drawUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y) { if (underlinedIndex >= 0 && underlinedIndex < text.length()) { // PENDING: this needs to change. FontMetrics fm = g.getFontMetrics(); int underlineRectX = x + fm.stringWidth(text.substring(0, underlinedIndex)); int underlineRectY = y; int underlineRectWidth = fm.charWidth(text.charAt(underlinedIndex)); int underlineRectHeight = 1; g.fillRect(underlineRectX, underlineRectY + 1, underlineRectWidth, underlineRectHeight); }//from w ww.jav a 2s. c o m } }