show Error Messages Dialog - Java Swing

Java examples for Swing:JOptionPane

Description

show Error Messages Dialog

Demo Code


//package com.java2s;
import java.awt.Component;
import java.util.Collection;
import java.util.Iterator;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class Main {
    public static void showErrorMessages(Component comp, Collection msgCol,
            String title) {/* w ww . j a v a 2s .c o m*/
        JLabel lab = new JLabel(getMsgContext(msgCol));
        JOptionPane.showOptionDialog(comp, // the parent that the dialog blocks
                lab, // the dialog message array
                title, // the title of the dialog window
                JOptionPane.OK_OPTION, // option type
                -1, // message type
                null, // optional icon, use null to use the default icon
                new String[] { "Okay" }, // options string array, will be made into buttons
                "Okay" // option that should be made into a default button
        );
    }

    private static final String getMsgContext(Collection errMsgPool) {
        StringBuffer buf = new StringBuffer("<html>");
        buf.append("<body>");
        buf.append("<ol>");
        for (Iterator iter = errMsgPool.iterator(); iter.hasNext();) {
            String msg = (String) iter.next();
            buf.append("<li>");
            buf.append(msg);
            buf.append("</li>");
        }
        buf.append("</ol>");
        buf.append("</body></html>");
        return buf.toString();
    }
}

Related Tutorials