Java Draw String drawStringPair(Graphics2D g, String str1, String str2, int left, int right, int y, int size, Color color, boolean bold)

Here you can find the source of drawStringPair(Graphics2D g, String str1, String str2, int left, int right, int y, int size, Color color, boolean bold)

Description

draw String Pair

License

Open Source License

Declaration

public static void drawStringPair(Graphics2D g, String str1, String str2, int left, int right, int y, int size,
            Color color, boolean bold) 

Method Source Code


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

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

public class Main {
    public static void drawStringPair(Graphics2D g, String str1, String str2, int left, int right, int y, int size,
            Color color, boolean bold) {
        drawStringLeft(g, str1, left, y, size, color, bold);
        drawStringRight(g, str2, right, y, size, color, bold);
    }/*from  w  w w . j av  a2 s . c o m*/

    public static void drawStringLeft(Graphics2D g, String text, Rectangle rect, int fontHeight, Color c) {
        Font f = new Font("Serif", Font.PLAIN, fontHeight);
        g.setFont(f);
        g.setColor(c);
        g.drawString(text, rect.x, rect.y + rect.height);
    }

    public static void drawStringLeft(Graphics2D g, String text, int x, int y, int fontHeight, Color c) {
        drawStringLeft(g, text, x, y, fontHeight, c, false);
    }

    public static void drawStringLeft(Graphics2D g, String text, int x, int y, int fontHeight, Color c,
            boolean bold) {
        Font f = new Font("Serif", bold ? Font.BOLD : Font.PLAIN, fontHeight);
        g.setFont(f);
        g.setColor(c);
        g.drawString(text, x, y);
    }

    public static void drawStringRight(Graphics2D g, String text, Rectangle rect, int fontHeight, Color c) {
        Font f = new Font("Serif", Font.PLAIN, fontHeight);
        g.setFont(f);
        FontMetrics fm = g.getFontMetrics();
        g.setColor(c);
        g.drawString(text, rect.x + rect.width - fm.stringWidth(text), rect.y + rect.height);
    }

    public static void drawStringRight(Graphics2D g, String text, int x, int y, int fontHeight, Color c) {
        drawStringRight(g, text, x, y, fontHeight, c, false);
    }

    public static void drawStringRight(Graphics2D g, String text, int x, int y, int fontHeight, Color c,
            boolean bold) {
        Font f = new Font("Serif", bold ? Font.BOLD : Font.PLAIN, fontHeight);
        g.setFont(f);
        FontMetrics fm = g.getFontMetrics();
        g.setColor(c);
        g.drawString(text, x - fm.stringWidth(text), y);
    }
}

Related

  1. drawStringEx(Graphics g1, String s, Font font, Rectangle rect, int align, int valign)
  2. drawStringInBox(Graphics g, String string, int x, int y)
  3. drawStringLeft(Graphics2D g, String text, Rectangle rect, int fontHeight, Color c)
  4. drawStringOnImage(Image image, String string, int x, int y)
  5. drawStringOnScreen(String s, Color color, long milseconds)
  6. drawStringRight(final Graphics g, final FontMetrics m, final String str, final int x, final int y)
  7. drawStringRightAlignedVTop(Graphics graphics, String string, int x, int yTop)
  8. drawStringUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y)
  9. drawStringVCentered(Graphics graphics, String string, int x, int upperY, int lowerY)