Here you can find the source of getStringHeight(Graphics2D g, String str)
private static double getStringHeight(Graphics2D g, String str)
//package com.java2s; import java.awt.font.FontRenderContext; import java.awt.font.GlyphVector; import java.awt.Graphics2D; public class Main { private static double getStringHeight(Graphics2D g, String str) { FontRenderContext frc = g.getFontRenderContext(); GlyphVector gv = g.getFont().createGlyphVector(frc, str); return gv.getPixelBounds(null, 0, 0).getHeight(); }/* www. java 2s . c o m*/ }