Here you can find the source of showErrorMessage(String title, String message, java.awt.Component parent)
Parameter | Description |
---|---|
title | The title of the dialog. |
message | The error message. |
parent | The owner of this dialog. |
public static void showErrorMessage(String title, String message, java.awt.Component parent)
//package com.java2s; //License from project: Open Source License import javax.swing.JOptionPane; public class Main { /**// www.ja v a2 s. co m * Displays an error message using the {@link JOptionPane#ERROR_MESSAGE} * variant of dialog. * <p> * <b>Note:</b> The error message will be split into 15-word long lines.</p> * * @param title The title of the dialog. * @param message The error message. * @param parent The owner of this dialog. */ public static void showErrorMessage(String title, String message, java.awt.Component parent) { JOptionPane.showMessageDialog(parent, splitIntoLines(message), title, JOptionPane.ERROR_MESSAGE); } /** * Splits a given string into lines comprised of 15 words each. Line breaks * added to {@code message} by the user will be honoured and treated as * paragraphs. * * @param message a string. * @return a {@code String} split into lines. */ public static String splitIntoLines(String message) { String[] messageSplitLineBreak = message.split("\n"); StringBuilder mainBuilder = new StringBuilder(); for (int i = 0; i < messageSplitLineBreak.length; i++) { String[] whiteSpaceSplit = messageSplitLineBreak[i].split(" "); StringBuilder tempBuilder = new StringBuilder(); for (int j = 0; j < whiteSpaceSplit.length; j++) { tempBuilder.append(whiteSpaceSplit[j]).append(" "); if (j != 0 && j % 14 == 0 && message.length() > tempBuilder.length() + mainBuilder.length()) { tempBuilder.append("\n"); } } mainBuilder.append(tempBuilder).append("\n"); } return mainBuilder.toString(); } }