Java JOptionPane Message showMessage(Component parent, String msg, String title, int flags)

Here you can find the source of showMessage(Component parent, String msg, String title, int flags)

Description

Shows a message dialog, wrapping the msg at 60 columns.

License

Mozilla Public License

Parameter

Parameter Description
parent a parameter
msg a parameter
title a parameter
flags a parameter

Declaration

public static void showMessage(Component parent, String msg, String title, int flags) 

Method Source Code


//package com.java2s;
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import java.awt.Component;

import javax.swing.JOptionPane;

public class Main {
    /**//from  w w w  . j  a v a  2s.com
     * Shows a message dialog, wrapping the {@code msg} at 60 columns.
     * 
     * @param parent
     * @param msg
     * @param title
     * @param flags
     */
    public static void showMessage(Component parent, String msg, String title, int flags) {
        if (msg != null && msg.length() > 60) {
            StringBuilder buf = new StringBuilder();
            final int L = msg.length();
            for (int i = 0, j = 0; i < L; i++, j++) {
                final char c = msg.charAt(i);
                buf.append(c);
                if (Character.isWhitespace(c)) {
                    int k;
                    for (k = i + 1; k < L; k++) {
                        if (Character.isWhitespace(msg.charAt(k))) {
                            break;
                        }
                    }
                    if (k < L) {
                        final int nextWordLen = k - i;
                        if (j + nextWordLen > 60) {
                            buf.append('\n');
                            j = 0;
                        }
                    }
                }
            }
            msg = buf.toString();
        }
        JOptionPane.showMessageDialog(parent, msg, title, flags);
    }
}

Related

  1. showMessage(Component c, String message, String title)
  2. showMessage(Component c, String msg)
  3. showMessage(Component component, String message)
  4. showMessage(Component item, String title)
  5. showMessage(Component parent, String message, int messageType)
  6. showMessage(Component parentComponent, String title, String message, int messageType)
  7. showMessage(final Component rootComponent, final String message, final String title)
  8. showMessage(final String message)
  9. showMessage(final String message)