Java Draw String drawStringAlignCenter(Graphics2D g2d, String s, int x, int y)

Here you can find the source of drawStringAlignCenter(Graphics2D g2d, String s, int x, int y)

Description

draw String Align Center

License

LGPL

Declaration

public static void drawStringAlignCenter(Graphics2D g2d, String s, int x, int y) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.awt.Graphics2D;

public class Main {
    public static void drawStringAlignCenter(Graphics2D g2d, String s, int x, int y) {
        int stringLen = (int) g2d.getFontMetrics().getStringBounds(s, g2d).getWidth();
        g2d.drawString(s, x - stringLen / 2, y);

    }//from w  w  w  . jav  a  2 s .c o m
}

Related

  1. drawString(Graphics2D gfx, String text, int x, int y)
  2. drawString(Graphics2D graphics, String text, double x, double y, boolean centerHorizontal, boolean centerVertical, Color backgroundColor)
  3. drawString(Image img, String text, Color color)
  4. drawString(String pString, Graphics2D pG, int pX, int pY, int pWidth, int pHeight, boolean pYOverflow, boolean pShrinkWords, String pJustification, boolean pDraw)
  5. drawString(String txt, int x, int y, Graphics g)
  6. drawStringAt(Graphics g, String t, int x, int y, int where)
  7. drawStringAtPoint(Graphics g, String s, Point p)
  8. drawStringEx(Graphics g1, String s, Font font, Rectangle rect, int align, int valign)
  9. drawStringInBox(Graphics g, String string, int x, int y)