Here you can find the source of getStringDrawingHeight(Graphics graphics, String string)
public static int getStringDrawingHeight(Graphics graphics, String string)
//package com.java2s; /*// w w w . ja v a 2 s .c o m * File: GraphicsHelper.java * Copyright (c) 2004-2007 Peter Kliem (Peter.Kliem@jaret.de) * A commercial license is available, see http://www.jaret.de. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ import java.awt.Graphics; import java.awt.geom.Rectangle2D; public class Main { public static int getStringDrawingHeight(Graphics graphics, String string) { Rectangle2D rect = graphics.getFontMetrics().getStringBounds(string, graphics); return (int) rect.getHeight() - graphics.getFontMetrics().getDescent(); } }