Here you can find the source of displayWarning(String strMsg)
public static void displayWarning(String strMsg)
//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 displayWarning(String strMsg) { displayMessageBox(strMsg, JOptionPane.WARNING_MESSAGE, false); }/* ww w . j a va2 s . com*/ 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(); } }