Java Font Text Width getStringWidth(Graphics2D g2, final String str)

Here you can find the source of getStringWidth(Graphics2D g2, final String str)

Description

get String Width

License

Open Source License

Declaration

public static int getStringWidth(Graphics2D g2, final String str) 

Method Source Code

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

import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;

public class Main {
    public static int getStringWidth(Graphics2D g2, final String str) {
        Rectangle2D bounds = g2.getFont().getStringBounds(str,
                g2.getFontRenderContext());
        return (int) bounds.getWidth();
    }//from www  .  j  a v a 2  s . c om
}

Related

  1. fontWidth(final Graphics graphics, final Font font, final String str)
  2. getStringWidth(final Font f, final String s)
  3. getStringWidth(Font font, String text)
  4. getStringWidth(FontMetrics f, String s)
  5. getStringWidth(Graphics g, Font font, String x)
  6. getStringWidth(Graphics2D g2d, String info, Font font)
  7. getStringWidth(String loginID, Font font)
  8. getStringWidth(String s, FontMetrics fm)
  9. getStringWidth(String str, java.awt.Font font)