Here you can find the source of drawStringVertical(Graphics graphics, String string, int x, int y)
Parameter | Description |
---|---|
graphics | graphics to paint with |
string | string to to draw |
x | upper left x |
y | upper left y |
public static void drawStringVertical(Graphics graphics, String string, int x, int y)
//package com.java2s; /*/*from w ww. j a v a2s . c om*/ * File: GraphicsHelper.java * Copyright (c) 2004-2007 Peter Kliem (Peter.Kliem@jaret.de) * A commercial license is available, see http://www.jaret.de. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; public class Main { /** * Draw a String vertical. This method might be quite costly since it uses an image to buffer. * * @param graphics graphics to paint with * @param string string to to draw * @param x upper left x * @param y upper left y */ public static void drawStringVertical(Graphics graphics, String string, int x, int y) { Rectangle2D rect = graphics.getFontMetrics().getStringBounds(string, graphics); BufferedImage img = new BufferedImage((int) rect.getWidth(), (int) rect.getHeight(), BufferedImage.TYPE_3BYTE_BGR); Graphics imageGraphics = img.getGraphics(); imageGraphics.setColor(Color.WHITE); imageGraphics.fillRect(0, 0, img.getWidth(), img.getHeight()); imageGraphics.setColor(Color.BLACK); imageGraphics.drawString(string, 0, (int) rect.getHeight()); BufferedImage vertImg = new BufferedImage((int) rect.getHeight(), (int) rect.getWidth(), BufferedImage.TYPE_3BYTE_BGR); for (int xx = 0; xx < img.getWidth(); xx++) { for (int yy = 0; yy < img.getHeight(); yy++) { vertImg.setRGB(yy, img.getWidth() - xx - 1, img.getRGB(xx, yy)); } } graphics.drawImage(vertImg, x, y, new ImageObserver() { public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { return false; } }); } }