Java Font Text Height getStringDrawingHeight(Graphics graphics, String string)

Here you can find the source of getStringDrawingHeight(Graphics graphics, String string)

Description

get String Drawing Height

License

Open Source License

Declaration

public static int getStringDrawingHeight(Graphics graphics, String string) 

Method Source Code

//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();
    }
}

Related

  1. getStringHeight(Component c)
  2. getStringHeight(Graphics2D g, String str)
  3. getStringHeight(Graphics2D graphics2D)
  4. getTextHeight(String s, FontMetrics fm, Graphics g)