Here you can find the source of drawMultilineText(final Graphics2D gc, final int x, int y, final String text)
Parameter | Description |
---|---|
gc | AWT Graphics context. Font must be set. |
x | X position of text (left edge) |
y | Y position of text's baseline |
text | Text to draw, may contain '\n' |
public static void drawMultilineText(final Graphics2D gc, final int x, int y, final String text)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010-2015-2016 Oak Ridge National Laboratory. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html ******************************************************************************/ import java.awt.Graphics2D; public class Main { /** Draw multi-line text * @param gc AWT Graphics context. Font must be set. * @param x X position of text (left edge) * @param y Y position of text's baseline * @param text Text to draw, may contain '\n' */// w w w. j av a2 s. co m public static void drawMultilineText(final Graphics2D gc, final int x, int y, final String text) { final int line_height = gc.getFontMetrics().getHeight(); for (String line : text.split("\n")) { gc.drawString(line, x, y); y += line_height; } } }