Here you can find the source of getTextWidth(String text, Graphics g, String newLineSplit)
public static int getTextWidth(String text, Graphics g, String newLineSplit)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics; public class Main { public static int getTextWidth(String text, Graphics g, String newLineSplit) { int width = 0; String[] lines = text.split(newLineSplit); for (String line : lines) { int w = g.getFontMetrics().stringWidth(line); if (w > width) { width = w;/*from www .j ava 2s. co m*/ } } return width; } }