Here you can find the source of getImage(String text, boolean clockwise, Font font, FontMetrics fm, Color bg, Color fontColor)
public static BufferedImage getImage(String text, boolean clockwise, Font font, FontMetrics fm, Color bg, Color fontColor)
//package com.java2s; //License from project: Academic Free License import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import javax.swing.JLabel; import javax.swing.SwingUtilities; public class Main { public static BufferedImage getImage(String text, boolean clockwise) { JLabel lbl = new JLabel(); Font f = lbl.getFont();/* w w w . j a va2 s . com*/ f = f.deriveFont(Font.BOLD); FontMetrics fm = lbl.getFontMetrics(f); Color bg = new Color(1f, 1f, 1f, 0.0f); Color fontColor = lbl.getForeground(); return getImage(text, clockwise, f, fm, bg, fontColor); } public static BufferedImage getImage(String text, boolean clockwise, Font font, FontMetrics fm, Color bg, Color fontColor) { BufferedImage bi = null; int width = SwingUtilities.computeStringWidth(fm, text); int height = fm.getHeight(); bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) bi.getGraphics(); g2.setColor(bg); g2.fillRect(0, 0, width, height); g2.setFont(font); g2.setColor(fontColor); g2.drawString(text, 0, fm.getLeading() + fm.getAscent()); return bi; } }