Here you can find the source of stringWidth(Graphics2D g, String s)
public static int stringWidth(Graphics2D g, String s)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics2D; public class Main { public static int stringWidth(Graphics2D g, String s) { return g.getFontMetrics().stringWidth(s); }//from ww w. j a v a2 s .c o m }