draw text to the screen with breaks

well how to bring lines of text onto the screen with breaks… ?

Graphics.drawString does not support \n so it seems, but System.out.print and so on do it of course…

how do you do this ?

Break it into pieces… draw it line by line. :slight_smile:

Here’s a simple method that takes a String-array and draws it at the specified corners.

(I haven’t actually tested it yet - not a lot of time at the moment - but it should work with no problem.)

public void drawStrings(Graphics g, String ln[], int x, int y) {
	FontMetrics fm = g.getFontMetrics(g.getFont());
	int h = fm.getHeight();

	for (int i=0; i<ln.length; i++) {
		g.drawString(ln[i], x, y+(h*i));
	}
}

Try this instead!

public void drawStrings(Graphics g, String ln[], int x, int y) {
	FontMetrics fm = g.getFontMetrics(g.getFont());
	int h = fm.getHeight();

	for (int i=0; i<ln.length; i++) {
		g.drawString(ln[i], x, y+(h*i) + h);
	}
}

thanks :smiley: