Here you can find the source of drawStackTrace(Graphics gr, int x, int y, Throwable ex)
private static void drawStackTrace(Graphics gr, int x, int y, Throwable ex)
//package com.java2s; /* ================================================================ * Cewolf : Chart enabling Web Objects Framework * ================================================================ * * Project Info: http://cewolf.sourceforge.net * Project Lead: Guido Laures (guido@laures.de); * * (C) Copyright 2002, by Guido Laures// www. java 2 s . com * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ import java.awt.Graphics; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Enumeration; import java.util.StringTokenizer; public class Main { private static void drawStackTrace(Graphics gr, int x, int y, Throwable ex) { final int linePadding = 4; int lineHeight = gr.getFont().getSize() + linePadding; int currY = y; Enumeration lines = new StringTokenizer(getStackTrace(ex), "\n", false); while (lines.hasMoreElements()) { gr.drawString(((String) lines.nextElement()).trim(), x, currY); currY += lineHeight; } } private static String getStackTrace(Throwable t) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); pw.close(); return sw.getBuffer().toString(); } }