Java examples for Swing:JOptionPane
Shows an informational message Dialog using the given title and message.
import java.awt.Component; import java.lang.reflect.InvocationTargetException; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import org.apache.log4j.Logger; public class Main{ /** Shows an informational message using the given title and message. */ public static void showInfoMessage(final String title, final String message) { showInfoMessage(title, message, null); }// www. j a v a 2 s . c om /** Shows an informational message using the given title and message. */ public static void showInfoMessage(final String title, final String message, final Component parentComponent) { showMessageDialog(title, message, JOptionPane.INFORMATION_MESSAGE, parentComponent); } /** Shows an informational message using the given title and message. */ private static void showMessageDialog(final String title, final String message, final int messageType, final Component parentComponent) { if (SwingUtilities.isEventDispatchThread()) { JOptionPane.showMessageDialog(parentComponent, message, title, messageType); } else { SwingUtils.runInGUIThread(new Runnable() { public void run() { JOptionPane.showMessageDialog(parentComponent, message, title, messageType); } }); } } }