Java tutorial
//package com.java2s; import java.awt.Graphics; public class Main { /** Draw 'str' at the given location, but process newlines by moving * to a new line. */ public static void drawTextWithNewlines(Graphics g, String str, int x, int y) { String lines[] = str.split("\n"); int lineHeight = g.getFontMetrics().getHeight(); for (String s : lines) { g.drawString(s, x, y); y += lineHeight; } } }