Java examples for 2D Graphics:Font
get Font Width
//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); } }