Java Font Text Width stringWidth(java.awt.Font font, String string)

Here you can find the source of stringWidth(java.awt.Font font, String string)

Description

Return a string width for a given font.

License

Open Source License

Declaration

public static int stringWidth(java.awt.Font font, String string) 

Method Source Code

//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());
    }
}

Related

  1. shrinkFontForWidth(Font base, String text, int desiredWidth, Graphics getMetrics)
  2. stringPixelWidth(String text, FontMetrics fm)
  3. stringWidth(final FontMetrics fm, final String string)
  4. stringWidth(Graphics g, String s)
  5. stringWidth(Graphics2D g, String s)
  6. stringWidth(String text, Font font)
  7. wrap(String str, FontMetrics fm, int maxWidth)
  8. wrapLineInto(String line, List list, FontMetrics fm, int maxWidth)