Java examples for 2D Graphics:Text
measure Text Pixels
//package com.java2s; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; public class Main { public static Dimension measureTextPixels(FontMetrics metrics, Font font, String text) { int width = metrics.stringWidth(text); int height = metrics.getHeight(); return new Dimension(width, height); }/*from w w w . j a va 2 s . co m*/ }