Java Font Text Width getStringWidth(FontMetrics f, String s)

Here you can find the source of getStringWidth(FontMetrics f, String s)

Description

get String Width

License

Open Source License

Declaration

public static int getStringWidth(FontMetrics f, String s) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.FontMetrics;

public class Main {
    public static int getStringWidth(FontMetrics f, String s) {
        int width = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) < 256)
                width += f.getWidths()[s.charAt(i)];
            else//from ww  w  . j  av  a 2 s .  c  om
                width += f.getWidths()['a'];
        }
        return width;
    }
}

Related

  1. findStringLimit(String aString, Font aFont, int aWidth)
  2. findWidth(FontMetrics metrics, char[] chars, int off, int len, float maxWidth, float[] outWidth)
  3. fontWidth(final Graphics graphics, final Font font, final String str)
  4. getStringWidth(final Font f, final String s)
  5. getStringWidth(Font font, String text)
  6. getStringWidth(Graphics g, Font font, String x)
  7. getStringWidth(Graphics2D g2, final String str)
  8. getStringWidth(Graphics2D g2d, String info, Font font)
  9. getStringWidth(String loginID, Font font)