Here you can find the source of getCenterOffset(Graphics g, Font f, char ch)
public static Point getCenterOffset(Graphics g, Font f, char ch)
//package com.java2s; import java.awt.Graphics; import java.awt.Point; import java.awt.Font; import java.awt.FontMetrics; public class Main { /**//from ww w.j a v a 2 s . c o m * Given a character and its font, calculate the center point offset * for that character. In otherwords, if the character were placed * at point (0,0), the result would be the center point of the * character. */ public static Point getCenterOffset(Graphics g, Font f, char ch) { FontMetrics fm = g.getFontMetrics(f); int xOffset = (int) (fm.charWidth(ch) / 2); int yOffset = (int) (fm.getAscent() / 2); return new Point(xOffset, yOffset); } }