Here you can find the source of drawStringAlignCenter(Graphics2D g2d, String s, int x, int y)
public static void drawStringAlignCenter(Graphics2D g2d, String s, int x, int y)
//package com.java2s; //License from project: LGPL import java.awt.Graphics2D; public class Main { public static void drawStringAlignCenter(Graphics2D g2d, String s, int x, int y) { int stringLen = (int) g2d.getFontMetrics().getStringBounds(s, g2d).getWidth(); g2d.drawString(s, x - stringLen / 2, y); }//from w w w . jav a 2 s .c o m }