Java Draw String drawStringRightAlignedVTop(Graphics graphics, String string, int x, int yTop)

Here you can find the source of drawStringRightAlignedVTop(Graphics graphics, String string, int x, int yTop)

Description

draw String Right Aligned V Top

License

Open Source License

Declaration

public static void drawStringRightAlignedVTop(Graphics graphics, String string, int x, int yTop) 

Method Source Code

//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);

    }
}

Related

  1. drawStringLeft(Graphics2D g, String text, Rectangle rect, int fontHeight, Color c)
  2. drawStringOnImage(Image image, String string, int x, int y)
  3. drawStringOnScreen(String s, Color color, long milseconds)
  4. drawStringPair(Graphics2D g, String str1, String str2, int left, int right, int y, int size, Color color, boolean bold)
  5. drawStringRight(final Graphics g, final FontMetrics m, final String str, final int x, final int y)
  6. drawStringUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y)
  7. drawStringVCentered(Graphics graphics, String string, int x, int upperY, int lowerY)
  8. drawStringVertical(Graphics graphics, String string, int x, int y)
  9. drawStringWithHighlighting(Graphics g, String s, int x, int y, Color foreground, Color highlighting)