Java JOptionPane Warning showWarningMessage(String title, String message, java.awt.Component parent)

Here you can find the source of showWarningMessage(String title, String message, java.awt.Component parent)

Description

show Warning Message

License

Open Source License

Declaration

public static void showWarningMessage(String title, String message, java.awt.Component parent) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.JOptionPane;

public class Main {
    public static void showWarningMessage(String title, String message, java.awt.Component parent) {
        JOptionPane.showMessageDialog(parent, splitIntoLines(message), title, JOptionPane.WARNING_MESSAGE);
    }//from w  w  w  .  jav a  2 s.  c om

    /**
     * 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();
    }
}

Related

  1. showWarningConfirmBox(Component pParent, String pMessage, String pTitle, String pLeftOption, String pRightOption)
  2. showWarningMessage(Component parent, String str)
  3. showWarningMessage(Component parent, String str)
  4. showWarningMessage(final Window aParent, final String aMessage)
  5. showWarningMessage(String message, Component component)
  6. warn(Component parent, String message)
  7. warn(Component parent, String message)
  8. warn(Component parent, String message)
  9. warn(String message)