Java Font Text Width getWidthForText(String txt, Font font)

Here you can find the source of getWidthForText(String txt, Font font)

Description

get Width For Text

License

Apache License

Declaration

public static int getWidthForText(String txt, Font font) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.Font;

import java.awt.Toolkit;

public class Main {
    public static int getWidthForText(String txt, Font font) {
        java.awt.FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(font);
        int width = fm.stringWidth(txt);
        return width;
    }/*from ww  w. j a  v a 2 s.  c o  m*/
}

Related

  1. getStringWidth(String s, FontMetrics fm)
  2. getStringWidth(String str, java.awt.Font font)
  3. getTextForWidth(double bboxWth, String txt, Font font)
  4. getTextWidth(String text, Graphics g, String newLineSplit)
  5. getWidth(String s, Graphics g)
  6. getWidthOfDots(FontMetrics fontMetrics)
  7. setFixedWidthFont(Component comp)
  8. shrinkFontForWidth(Font base, String text, int desiredWidth, Graphics getMetrics)
  9. stringPixelWidth(String text, FontMetrics fm)