Java Graphics Draw String drawRightJustifiedText(String text, int right, int y, Graphics g)

Here you can find the source of drawRightJustifiedText(String text, int right, int y, Graphics g)

Description

Draw a block of text right justified to the given location

License

LGPL

Parameter

Parameter Description
text a parameter
right a parameter
y a parameter
g a parameter

Declaration


public static void drawRightJustifiedText(String text, int right, int y, Graphics g) 

Method Source Code


//package com.java2s;
/*//from w w w  . j av  a2s  . c om
 * Copyright (c) 2007-2012 The Broad Institute, Inc.
 * SOFTWARE COPYRIGHT NOTICE
 * This software and its documentation are the copyright of the Broad Institute, Inc. All rights are reserved.
 *
 * This software is supplied without any warranty or guaranteed support whatsoever. The Broad Institute is not responsible for its use, misuse, or functionality.
 *
 * This software is licensed under the terms of the GNU Lesser General Public License (LGPL),
 * Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php.
 */

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class Main {
    /**
     * Draw a block of text right justified to the given location
     *
     * @param text
     * @param right
     * @param y
     * @param g
     */

    public static void drawRightJustifiedText(String text, int right, int y, Graphics g) {
        FontMetrics fontMetrics = g.getFontMetrics();

        Rectangle2D textBounds = fontMetrics.getStringBounds(text, g);
        int x = right - (int) textBounds.getWidth();
        g.drawString(text, x, y);

    }
}

Related

  1. drawGradient(Graphics g, JComponent c, String prefix)
  2. drawGradientText(Graphics g, String text, int x, int y, Color c)
  3. drawLine(String pLine, Graphics2D pG, int pX, int pY, int pWidth, String pJustification)
  4. drawLineDrawChar(Graphics g, int x, int y, int bi, char c, int charWidth, int charHeight)
  5. drawMessage(Graphics2D g, String message)
  6. drawRightText(Graphics g, String str, int x, int y, int width, int height)
  7. drawRotatedShape(final Shape shape, final Graphics2D g2, final float x, final float y, final double angle)
  8. drawScaleLabel(Graphics g, String label, int x, int y, boolean yAxisP)
  9. drawSystemNameLabel(Graphics2D g, String sysName, Color color, double safetyOffset, boolean isLocationKnownUpToDate)