measure Text Pixels - Java 2D Graphics

Java examples for 2D Graphics:Text

Description

measure Text Pixels

Demo Code


//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*/
}

Related Tutorials