Here you can find the source of getStringWidth(Font font, String text)
Parameter | Description |
---|---|
font | the font |
text | the text |
public static int getStringWidth(Font font, String text)
//package com.java2s; import java.awt.Font; import java.awt.Graphics2D; public class Main { /** The dummy gfx. */ private static Graphics2D dummyGFX; /**/*w w w . ja va2 s .c om*/ * Gets the string width. * * @param font * the font * @param text * the text * @return the string width */ public static int getStringWidth(Font font, String text) { dummyGFX.setFont(font); return dummyGFX.getFontMetrics().stringWidth(text); } }