Java Font Text Bounds getTextBounds(final Graphics2D graphics, final String text, final Font font)

Here you can find the source of getTextBounds(final Graphics2D graphics, final String text, final Font font)

Description

get Text Bounds

License

Open Source License

Declaration

public static Rectangle2D getTextBounds(final Graphics2D graphics, final String text, final Font font) 

Method Source Code

//package com.java2s;
/*//from   w  ww . j a v a 2  s .com
 * Copyright ? 2016 spypunk <spypunk@gmail.com>
 *
 * This work is free. You can redistribute it and/or modify it under the
 * terms of the Do What The Fuck You Want To Public License, Version 2,
 * as published by Sam Hocevar. See the COPYING file for more details.
 */

import java.awt.Font;
import java.awt.Graphics2D;

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

public class Main {
    public static Rectangle2D getTextBounds(final Graphics2D graphics, final String text, final Font font) {
        final FontRenderContext frc = graphics.getFontRenderContext();
        final GlyphVector gv = font.createGlyphVector(frc, text);

        return gv.getVisualBounds();
    }
}

Related

  1. getStringBounds(Graphics2D g2, String str, float x, float y)
  2. getStringBounds(Graphics2D g2d, String text, int x, int y)
  3. getStringBounds(String s, Graphics g)
  4. getStringBounds(String str, java.awt.Font font)
  5. getTextBounds(AttributedString text, Graphics2D g2)
  6. getTextBounds(final String text, final Graphics g, final Font font)
  7. getTextBounds(Graphics g, Font font, String text, int x, int y, int halign, int valign)
  8. getTextBounds(Graphics g, String text)
  9. getTextBounds(Graphics graphics, String text)