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)
public static void drawStringPair(Graphics2D g, String str1, String str2, int left, int right, int y, int size, Color color, boolean bold)
//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); } }