Java examples for 2D Graphics:Text
Getting the Shape from the Outline of Text
import java.awt.Font; import java.awt.Graphics2D; import java.awt.Shape; import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; public class Main { Shape getTextShape(Graphics2D g2d, String str, Font font) { FontRenderContext frc = g2d.getFontRenderContext(); TextLayout tl = new TextLayout(str, font, frc); return tl.getOutline(null); }// ww w .j a va2 s .c om }