Here you can find the source of stringDimension(Graphics g, Font f, String s)
Parameter | Description |
---|---|
g | the graphic environment |
f | the font environment |
s | the string to display |
public static Dimension stringDimension(Graphics g, Font f, String s)
//package com.java2s; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; public class Main { /**//from ww w . j a v a 2 s. c o m * Returns the dimension of the specified string <tt>s</tt> in specified * graphic and font environment. * * @param g * the graphic environment * @param f * the font environment * @param s * the string to display * @return the dimension of the string */ public static Dimension stringDimension(Graphics g, Font f, String s) { FontMetrics fm = g.getFontMetrics(f); return new Dimension(fm.stringWidth(s), fm.getHeight()); } }