Here you can find the source of stringWidth(java.awt.Font font, String string)
public static int stringWidth(java.awt.Font font, String string)
//package com.java2s; /*// w ww .j a va 2s . com * Copyright (c) Leuville Objects All Rights Reserved. * * Leuville Objects MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. Leuville Objects SHALL NOT BE LIABLE FOR * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ public class Main { /** * Return a string width for a given font. */ public static int stringWidth(java.awt.Font font, String string) { return (int) (0.6 * font.getSize() * string.length()); } }