Here you can find the source of getTextHeight(String s, FontMetrics fm, Graphics g)
public static int getTextHeight(String s, FontMetrics fm, Graphics g)
//package com.java2s; //License from project: Open Source License import java.awt.FontMetrics; import java.awt.Graphics; public class Main { public static int getTextHeight(String s, FontMetrics fm, Graphics g) { return (int) Math.ceil(fm.getLineMetrics(s, g).getHeight()); }/*from w ww. jav a 2 s. c o m*/ }