Java Graphics Draw String drawUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y)

Here you can find the source of drawUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y)

Description

draw Underline Char At

License

Apache License

Declaration

public static void drawUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y) 

Method Source Code

//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
    }
}

Related

  1. drawText(Graphics graphics, int x, int y, String text)
  2. drawText(Graphics2D graphics, Font font, Dimension2D dimension, String text)
  3. drawTextCenter(Graphics2D g2, String str, int x, int y)
  4. drawTextInBoundedArea(Graphics2D g2d, int x1, int y1, int x2, int y2, String text)
  5. drawTuplet(Graphics g, int x, int y, int x2, int y2, int bi, String s1, String s2)
  6. drawVerticalText(Graphics2D graphics, Font font, Dimension2D dimension, String text)
  7. drawVerticalTextCenter(Graphics2D g2, String str, int x, int y)
  8. drawWrappedText(Graphics2D g2, float x, float y, float width, String text)
  9. paintCenteredString(Graphics2D g, String str, Font font, int centerX, int centerY)