Java examples for 2D Graphics:Text
measure String Height
//package com.java2s; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; public class Main { public static int measureStringHeight(Graphics g, String s) { return (int) g .getFont()//from w w w . j av a2s.c om .getStringBounds(s, ((Graphics2D) g).getFontRenderContext()) .getHeight(); } public static int measureStringHeight(Graphics g, Font f, String s) { return (int) f.getStringBounds(s, ((Graphics2D) g).getFontRenderContext()).getHeight(); } }