Java Font Text Bounds getStringBounds(Graphics2D g2, String str, float x, float y)

Here you can find the source of getStringBounds(Graphics2D g2, String str, float x, float y)

Description

get String Bounds

License

Open Source License

Declaration

public static Rectangle getStringBounds(Graphics2D g2, String str, float x, float y) 

Method Source Code


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

import java.awt.Graphics2D;
import java.awt.Rectangle;

import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;

public class Main {
    public static Rectangle getStringBounds(Graphics2D g2, String str, float x, float y) {
        FontRenderContext frc = g2.getFontRenderContext();
        GlyphVector gv = g2.getFont().createGlyphVector(frc, str);
        return gv.getPixelBounds(null, x, y);
    }/*from w w  w  .ja  va2s . co m*/
}

Related

  1. getStringBounds(Graphics2D g, Font font, String s)
  2. getStringBounds(Graphics2D g2, String s)
  3. getStringBounds(Graphics2D g2d, String text, int x, int y)
  4. getStringBounds(String s, Graphics g)
  5. getStringBounds(String str, java.awt.Font font)
  6. getTextBounds(AttributedString text, Graphics2D g2)