Java Graphics Draw String centerStringY(String s, int h, Graphics2D g2d)

Here you can find the source of centerStringY(String s, int h, Graphics2D g2d)

Description

center String Y

License

Open Source License

Declaration

public static int centerStringY(String s, int h, Graphics2D g2d) 

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 int centerStringY(String s, int h, Graphics2D g2d) {
        FontRenderContext frc = g2d.getFontRenderContext();
        GlyphVector gv = g2d.getFont().createGlyphVector(frc, s);
        Rectangle vb = gv.getVisualBounds().getBounds();

        return h / 2 - vb.height / 2 - vb.y;
    }/*  ww  w .  ja  va2  s.c om*/
}

Related

  1. centerString(Graphics g, String s, Font f, int w0, int w, int h)
  2. centerStringX(String s, int w, Graphics2D g2d)
  3. drawCentered(Graphics g, String text, Point p)
  4. drawCenteredChar(Graphics g, char[] chars, int x, int y, int w, int h)
  5. drawCenteredString(Graphics g, Rectangle rect, String str)
  6. drawCenteredString(Graphics g, String str, int x, int y)