Java tutorial
//package com.java2s; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import javax.swing.JComponent; public class Main { public static FontMetrics getFontMetrics(JComponent c, Graphics g) { Font font = g.getFont(); if (c != null) { return c.getFontMetrics(g.getFont()); } return g.getFontMetrics(font); } }