Here you can find the source of showError(final Component component, final String title, final String message)
Parameter | Description |
---|---|
component | component |
title | title |
message | message |
public static void showError(final Component component, final String title, final String message)
//package com.java2s; /*//from w w w.java2 s .co m * SK's Minecraft Launcher * Copyright (C) 2010, 2011 Albert Pham <http://www.sk89q.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.Component; import java.lang.reflect.InvocationTargetException; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; public class Main { /** * Shows an error dialog. * * <p>This can be called from a different thread from the event dispatch * thread, and it will be made thread-safe.</p> * * @param component component * @param title title * @param message message */ public static void showError(final Component component, final String title, final String message) { if (!SwingUtilities.isEventDispatchThread()) { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { showError(component, title, message); } }); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (InvocationTargetException e) { throw new RuntimeException(e); } return; } String newMessage = message.replace(">", ">").replace("<", "<").replace("&", "&"); newMessage = "<html>" + newMessage; JOptionPane.showMessageDialog(component, newMessage, title, JOptionPane.ERROR_MESSAGE); } /** * Invoke, wait, and ignore errors. * * @param runnable a runnable */ public static void invokeAndWait(Runnable runnable) { try { SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (InvocationTargetException e) { throw new RuntimeException(e); } } }