Java Graphics Draw String drawVerticalTextCenter(Graphics2D g2, String str, int x, int y)

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

Description

draw Vertical Text Center

License

Open Source License

Declaration

public static void drawVerticalTextCenter(Graphics2D g2, String str,
            int x, int y) 

Method Source Code

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

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

public class Main {
    private static final double NINETY_DEGREES = Math.toRadians(90.0);

    public static void drawVerticalTextCenter(Graphics2D g2, String str,
            int x, int y) {
        int strWidth = getStringWidth(g2, str);
        drawVerticalText(g2, str, x + g2.getFontMetrics().getHeight() / 2,
                y + strWidth / 2);/*from  w w  w.java 2  s  .  co  m*/
    }

    public static int getStringWidth(Graphics2D g2, final String str) {
        Rectangle2D bounds = g2.getFont().getStringBounds(str,
                g2.getFontRenderContext());
        return (int) bounds.getWidth();
    }

    public static void drawVerticalText(Graphics2D g2, String str, int x,
            int y) {
        g2.translate(x, y);
        g2.rotate(-NINETY_DEGREES);
        g2.drawString(str, 0, 0);
        g2.rotate(NINETY_DEGREES);
        g2.translate(-x, -y);
    }
}

Related

  1. drawTextCenter(Graphics2D g2, String str, int x, int y)
  2. drawTextInBoundedArea(Graphics2D g2d, int x1, int y1, int x2, int y2, String text)
  3. drawTuplet(Graphics g, int x, int y, int x2, int y2, int bi, String s1, String s2)
  4. drawUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y)
  5. drawVerticalText(Graphics2D graphics, Font font, Dimension2D dimension, String text)
  6. drawWrappedText(Graphics2D g2, float x, float y, float width, String text)
  7. paintCenteredString(Graphics2D g, String str, Font font, int centerX, int centerY)
  8. paintOutline(Graphics g, String s, int textX, int textY, int thickness)
  9. paintShadowTitleFat(Graphics g, String title, int x, int y, Color frente, Color shadow, int desp)