get Font Width - Java 2D Graphics

Java examples for 2D Graphics:Font

Description

get Font Width

Demo Code


//package com.java2s;

import java.awt.Font;
import java.awt.FontMetrics;

import java.awt.Graphics;

public class Main {
    public static int getFontWidth(Graphics offLineBuffer, Font font,
            String text) {/*from w  ww .j  av a 2  s .  c om*/
        offLineBuffer.setFont(font);
        FontMetrics fontmetrics = offLineBuffer.getFontMetrics();
        return fontmetrics.stringWidth(text);
    }
}

Related Tutorials