Here you can find the source of drawStringRightAlignedVTop(Graphics graphics, String string, int x, int yTop)
public static void drawStringRightAlignedVTop(Graphics graphics, String string, int x, int yTop)
//package com.java2s; /*/*w ww . j a va 2 s . com*/ * 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.Graphics; import java.awt.geom.Rectangle2D; public class Main { public static void drawStringRightAlignedVTop(Graphics graphics, String string, int x, int yTop) { Rectangle2D rect = graphics.getFontMetrics().getStringBounds(string, graphics); int xx = (int) (x - rect.getWidth()); int yy = (int) (yTop + rect.getHeight()); graphics.drawString(string, xx, yy); } }