Java FontMetrics getStringLengthInPixels(String s, Graphics g)

Here you can find the source of getStringLengthInPixels(String s, Graphics g)

Description

get String Length In Pixels

License

Open Source License

Declaration

@SuppressWarnings("deprecation")
    public static int getStringLengthInPixels(String s, Graphics g) 

Method Source Code


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

import java.awt.Graphics;
import java.awt.Toolkit;

public class Main {
    @SuppressWarnings("deprecation")
    public static int getStringLengthInPixels(String s, Graphics g) {
        return Toolkit.getDefaultToolkit().getFontMetrics(g.getFont()).stringWidth(s);
    }//  w w  w.j a  v  a2  s  .  com
}

Related

  1. getMonospacedFontNames()
  2. getMonospacedFontsFamillyName()
  3. getPrefSize(FontMetrics fm, String keyTip)
  4. getStringForMaxWidth(FontMetrics fm, String s, int maxWidth)
  5. getStringImage(Font font, String... strs)
  6. getStringRect(Font f, String s)
  7. getTextCenterShear(final FontMetrics fm, final String text)
  8. getTextCenterShearX(final FontMetrics fm, final String text)
  9. limitWithEllipsis(String str, Font font, int maxWidth, Component c)