Java JOptionPane Info displayInformation(String strMsg)

Here you can find the source of displayInformation(String strMsg)

Description

display Information

License

Apache License

Declaration

public static void displayInformation(String strMsg) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.EventQueue;

import java.awt.KeyboardFocusManager;

import java.awt.Window;

import javax.swing.JOptionPane;

public class Main {
    public static void displayInformation(String strMsg) {
        displayMessageBox(strMsg, JOptionPane.INFORMATION_MESSAGE, false);
    }//from w ww.j  ava2 s .co m

    public static void displayMessageBox(String strMsg, final int iType, boolean bWrapText) {
        final String strWrappedMsg = bWrapText ? wrapText(strMsg) : strMsg;

        Runnable logMsgBox = new Runnable() {
            public void run() {
                JOptionPane.showMessageDialog(getWindow(), strWrappedMsg, "", iType);
            }
        };

        if (EventQueue.isDispatchThread()) {
            logMsgBox.run();
        } else {
            try {
                EventQueue.invokeAndWait(logMsgBox);
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    }

    public static String wrapText(String strText) {
        return wrapText(strText, 60);
    }

    public static String wrapText(String strText, int iLineLen) {
        StringBuilder sb = new StringBuilder();
        while (strText != null) {
            if (strText.length() > iLineLen) {
                sb.append(strText.substring(0, 60)).append("\n");
                strText = strText.substring(60);
            } else {
                sb.append(strText);
                strText = null;
            }
        }
        return sb.toString();
    }

    public static Window getWindow() {
        return KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    }

    public static Window getFocusedWindow() {
        return KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    }
}

Related

  1. displayInfoPane(Component parentComponent, String message)
  2. displayInformationMessage(Component parentComponent, String message, String windowTitle)
  3. flashInfoMessage(final Component sourceComponent, final String message, int durationInMilliSecs)
  4. getIconInformation()
  5. info(Component component, String title, String msg)