Java JTable Row createThrowableMessage(Throwable t)

Here you can find the source of createThrowableMessage(Throwable t)

Description

create Throwable Message

License

Open Source License

Declaration

private static Object createThrowableMessage(Throwable t) 

Method Source Code


//package com.java2s;
/*//from   w ww .j  a  v  a 2 s. co  m
 *  Copyright (C) 2013, Peter Decsi.
 * 
 *  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 3 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 General Public License
 *  along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.BorderLayout;
import java.awt.Color;

import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class Main {
    private final static String ERR_LINE_FORMAT = "%n\t%s.%s(line: %d)";

    private static Object createThrowableMessage(Throwable t) {
        JPanel panel = new JPanel(new BorderLayout(12, 12));
        panel.add(new JLabel(t.getLocalizedMessage()), BorderLayout.NORTH);

        JTextArea stackTrace = new JTextArea();
        stackTrace.setForeground(Color.red);
        stackTrace.setColumns(50);
        stackTrace.setEditable(false);
        stackTrace.setTabSize(4);
        stackTrace.setText(toString(t));
        JScrollPane scroll = new JScrollPane(stackTrace);
        scroll.setPreferredSize(new Dimension(600, 200));
        panel.add(scroll, BorderLayout.CENTER);

        return panel;
    }

    private static String toString(Throwable t) {
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;
        while (t != null) {
            appendThrowable(t, sb, isFirst);
            t = t.getCause();
            isFirst = false;
        }

        return sb.toString();
    }

    private static void appendThrowable(Throwable t, StringBuilder sb, boolean isFirst) {
        if (!isFirst)
            sb.append("\nCaused by: ");
        sb.append(t.getClass().getName()).append(": ").append(t.getLocalizedMessage());

        for (StackTraceElement e : t.getStackTrace())
            sb.append(String.format(ERR_LINE_FORMAT, e.getClassName(), e.getMethodName(), e.getLineNumber()));
    }
}

Related

  1. checkRow(DefaultTableModel table, List data, int row)
  2. clearAllRows(JTable table)
  3. contains(int row, TableModel model)
  4. copyRows(JTable table)
  5. createDBXMLFile(JTable table, String docField, String rowField, Connection con, boolean reuseConnection, String driver, String dsn, String user, String password, String tableName, String whereString, String orderByString, String groupByString, boolean convertCharsToEntites)
  6. deleteRows(final int[] sortedRows, final List list, final AbstractTableModel model)
  7. ensureRowCount(int count, JTable table)
  8. firstRowIsVoid(TableModel model)
  9. getModelRowAtPoint(JTable table, Point point)