Example usage for javax.swing JOptionPane ERROR_MESSAGE

List of usage examples for javax.swing JOptionPane ERROR_MESSAGE

Introduction

In this page you can find the example usage for javax.swing JOptionPane ERROR_MESSAGE.

Prototype

int ERROR_MESSAGE

To view the source code for javax.swing JOptionPane ERROR_MESSAGE.

Click Source Link

Document

Used for error messages.

Usage

From source file:com.devbury.desktoplib.systemtray.SystemTrayApplication.java

public void start() {
    logSystemInfo();/*  www . j  av  a2  s . c  om*/
    try {
        if (!isSystemTraySupported()) {
            JOptionPane.showMessageDialog(null,
                    "Could not start application.  This application requires system tray support and your platform "
                            + "does not provide this.",
                    "System Tray Not Supported", JOptionPane.ERROR_MESSAGE);
            throw new RuntimeException("SystemTray is not supported");
        } else {
            logger.debug("SystemTray is supported");
        }
        if (applicationContext == null) {
            String[] locations = buildConfigLocations();
            logger.debug("Creating context from " + configLocationsToString(locations));
            applicationContext = new ClassPathXmlApplicationContext(locations);
            logger.debug("Context finished building");
        }
        // get the TrayIconDefinition instances
        Map defs = applicationContext.getBeansOfType(TrayIconDefinition.class);
        if (defs == null || defs.isEmpty()) {
            throw new RuntimeException("No TrayIconDefinition instances exist in the context");
        }
        SystemTray tray = newSystemTray();
        Iterator<TrayIconDefinition> it = defs.values().iterator();
        LinkedList<TrayIcon> installedIcons = new LinkedList<TrayIcon>();
        while (it.hasNext()) {
            TrayIconDefinition def = (TrayIconDefinition) it.next();
            try {
                TrayIcon ti = def.buildTrayIcon();
                tray.add(ti);
                installedIcons.add(ti);
            } catch (Throwable t) {
                logger.error("Could not add TrayIconDefinition " + def);
            }
        }
        // get the monitor object out of the context to block on
        Object monitor = applicationContext.getBean("applicationShutdownService");

        // if there was a splash screen shut it down
        SplashScreen splash = newSplashScreen();
        if (splash != null) {
            logger.debug("Shutting down splash screen");
            splash.close();
        }

        synchronized (monitor) {
            monitor.wait();
        }
        logger.debug("Application shutting down");
        Iterator<TrayIcon> trayIconIt = installedIcons.iterator();
        while (trayIconIt.hasNext()) {
            TrayIcon ti = (TrayIcon) trayIconIt.next();
            tray.remove(ti);
        }
        applicationContext.close();
        logger.debug("Application stopped");
    } catch (Throwable t) {
        logger.error("Unresolved exception", t);
        logger.error("Application shutting down");
        if (applicationContext != null) {
            applicationContext.close();
        }
        logger.error("Application stopped");
    }
}

From source file:ExecDemoNS.java

/** Start the help, in its own Thread. */
public void runProg() {

    new Thread() {
        public void run() {

            try {
                // Get the URL for the Help File
                URL helpURL = this.getClass().getClassLoader().getResource(HELPFILE);

                // Start Netscape from the Java Application.

                pStack.push(Runtime.getRuntime().exec(program + " " + helpURL));

            } catch (Exception ex) {
                JOptionPane.showMessageDialog(ExecDemoNS.this, "Error" + ex, "Error",
                        JOptionPane.ERROR_MESSAGE);
            }// ww w.ja v a  2s.  co  m
        }
    }.start();

}

From source file:cl.almejo.vsim.gui.actions.preferences.ColorPreferences.java

public ColorPreferences(Component parent) {
    _parent = parent;/* w w  w.j  a  va  2 s.  c  o m*/
    setBorder(new EmptyBorder(10, 10, 10, 10));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    JPanel pickers = new JPanel();
    pickers.setLayout(new GridLayout(10, 2));

    pickers.add(new Label(Messages.t("preferences.color.scheme.current.label")));
    _comboBox = createSchemeCombobox();
    pickers.add(_comboBox);

    addColorChooser(pickers, "gates");
    addColorChooser(pickers, "background");
    addColorChooser(pickers, "bus-on");
    addColorChooser(pickers, "ground");
    addColorChooser(pickers, "off");
    addColorChooser(pickers, "wires-on");
    addColorChooser(pickers, "signal");
    addColorChooser(pickers, "grid");
    addColorChooser(pickers, "label");
    add(pickers);

    JPanel buttons = new JPanel();
    JButton button = new JButton(Messages.t("preferences.color.scheme.save.label"));
    buttons.add(button);
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                FileUtils.writeStringToFile(new File("colors.json"), ColorScheme.save());
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    });
    button = new JButton(Messages.t("preferences.color.scheme.new.label"));
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String themeName = JOptionPane.showInputDialog(Messages.t("color.scheme.dialog.new.title"), "");
            if (themeName != null) {
                while (ColorScheme.exists(themeName)) {
                    JOptionPane.showMessageDialog(_parent,
                            Messages.t("color.scheme.dialog.already.exists.error"), "Error",
                            JOptionPane.ERROR_MESSAGE);
                    themeName = JOptionPane.showInputDialog(this, themeName);
                }
                ColorScheme.add(themeName);
                _comboBox.addItem(themeName);
                _comboBox.setSelectedItem(themeName);
            }
        }
    });
    buttons.add(button);
    add(buttons);
}

From source file:net.sf.jabref.external.FindFullTextAction.java

@Override
public void update() {
    if (result.isPresent()) {
        List<String> dirs = basePanel.getBibDatabaseContext().getFileDirectory();
        if (dirs.isEmpty()) {
            JOptionPane.showMessageDialog(basePanel.frame(),
                    Localization.lang("Main file directory not set!") + " " + Localization.lang("Preferences")
                            + " -> " + Localization.lang("External programs"),
                    Localization.lang("Directory not found"), JOptionPane.ERROR_MESSAGE);
            return;
        }// w w w  .j av  a 2s .  co  m
        String bibtexKey = entry.getCiteKey();
        // TODO: this needs its own thread as it blocks the UI!
        DownloadExternalFile def = new DownloadExternalFile(basePanel.frame(),
                basePanel.getBibDatabaseContext(), bibtexKey);
        try {
            def.download(result.get(), file -> {
                FileListTableModel tm = new FileListTableModel();
                entry.getFieldOptional(FieldName.FILE).ifPresent(tm::setContent);
                tm.addEntry(tm.getRowCount(), file);
                String newValue = tm.getStringRepresentation();
                UndoableFieldChange edit = new UndoableFieldChange(entry, FieldName.FILE,
                        entry.getFieldOptional(FieldName.FILE).orElse(null), newValue);
                entry.setField(FieldName.FILE, newValue);
                basePanel.getUndoManager().addEdit(edit);
                basePanel.markBaseChanged();
            });
        } catch (IOException e) {
            LOGGER.warn("Problem downloading file", e);
        }
        basePanel.output(Localization.lang("Finished downloading full text document"));
    } else {
        String message = Localization.lang("Full text document download failed");
        basePanel.output(message);
        JOptionPane.showMessageDialog(basePanel.frame(), message, message, JOptionPane.ERROR_MESSAGE);
    }
}

From source file:de.bfs.radon.omsimulation.gui.data.OMExports.java

/**
 * //from  w ww.j a  va2  s.co m
 * Method to export charts as PDF files using the defined path.
 * 
 * @param path
 *          The filename and absolute path.
 * @param chart
 *          The JFreeChart object.
 * @param width
 *          The width of the PDF file.
 * @param height
 *          The height of the PDF file.
 * @param mapper
 *          The font mapper for the PDF file.
 * @param title
 *          The title of the PDF file.
 * @throws IOException
 *           If writing a PDF file fails.
 */
@SuppressWarnings("deprecation")
public static void exportPdf(String path, JFreeChart chart, int width, int height, FontMapper mapper,
        String title) throws IOException {
    File file = new File(path);
    FileOutputStream pdfStream = new FileOutputStream(file);
    BufferedOutputStream pdfOutput = new BufferedOutputStream(pdfStream);
    Rectangle pagesize = new Rectangle(width, height);
    Document document = new Document();
    document.setPageSize(pagesize);
    document.setMargins(50, 50, 50, 50);
    document.addAuthor("OMSimulationTool");
    document.addSubject(title);
    try {
        PdfWriter pdfWriter = PdfWriter.getInstance(document, pdfOutput);
        document.open();
        PdfContentByte contentByte = pdfWriter.getDirectContent();
        PdfTemplate template = contentByte.createTemplate(width, height);
        Graphics2D g2D = template.createGraphics(width, height, mapper);
        Double r2D = new Rectangle2D.Double(0, 0, width, height);
        chart.draw(g2D, r2D);
        g2D.dispose();
        contentByte.addTemplate(template, 0, 0);
    } catch (DocumentException de) {
        JOptionPane.showMessageDialog(null, "Failed to write PDF document.\n" + de.getMessage(), "Failed",
                JOptionPane.ERROR_MESSAGE);
        de.printStackTrace();
    }
    document.close();
}

From source file:com.mightypocket.ashot.AShot.java

void showErrorMessage(String messageKey, Object... args) {
    ResourceMap resourceMap = getContext().getResourceMap();
    String message = resourceMap.getString(messageKey, args);
    String errorTitle = resourceMap.getString("error.title");

    JOptionPane.showMessageDialog(getMainFrame(), message, errorTitle, JOptionPane.ERROR_MESSAGE);
}

From source file:de.atomfrede.tools.evalutation.util.DialogUtil.java

public int showErrorDialog(String title, String errorMessage) {
    JOptionPane.showMessageDialog(frame, errorMessage, title, JOptionPane.ERROR_MESSAGE,
            Icons.IC_DIALOG_ERROR_LARGE);
    return 0;//from   w w w  .j a  v a 2 s  .  c  om
}

From source file:net.sf.jabref.gui.worker.VersionWorker.java

@Override
public void done() {
    if (this.isCancelled()) {
        return;//ww  w  . java  2  s  .com
    }

    try {
        Version latestVersion = this.get();

        if (latestVersion == null) {
            String couldNotConnect = Localization.lang("Couldn't connect to the update server.");
            String tryLater = Localization.lang("Please try again later and/or check your network connection.");
            if (manualExecution) {
                JOptionPane.showMessageDialog(this.mainFrame, couldNotConnect + "\n" + tryLater,
                        couldNotConnect, JOptionPane.ERROR_MESSAGE);
            }
            this.mainFrame.output(couldNotConnect + " " + tryLater);
            return;
        }

        // only respect the ignored version on automated version checks
        if (latestVersion.equals(toBeIgnored) && !manualExecution) {
            return;
        }

        boolean newer = latestVersion.isNewerThan(installedVersion);
        if (newer) {
            new NewVersionDialog(this.mainFrame, installedVersion, latestVersion, toBeIgnored);
            return;
        }

        String upToDate = Localization.lang("JabRef is up-to-date.");
        if (manualExecution) {
            JOptionPane.showMessageDialog(this.mainFrame, upToDate, upToDate, JOptionPane.INFORMATION_MESSAGE);
        }
        this.mainFrame.output(upToDate);

    } catch (InterruptedException | ExecutionException e) {
        LOGGER.error("Error while checking for updates", e);
    }
}

From source file:com.edduarte.protbox.core.Constants.java

public static BufferedImage getAsset(String resourceFileName) {
    BufferedImage result = cachedAssets.get(resourceFileName);

    if (result == null) {
        try {/* ww  w.j  ava 2  s.com*/
            InputStream stream = Protbox.class.getResourceAsStream(resourceFileName);
            result = ImageIO.read(stream);
            cachedAssets.put(resourceFileName, result);

        } catch (IOException | IllegalArgumentException ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(null,
                    "Asset file " + resourceFileName + " not detected or corrupted!\n"
                            + "Please reinstall the application.",
                    "Nonexistent or corrupted asset file", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
    }
    return result;
}

From source file:JuliaSet2.java

public void print() {
    // Java 1.1 used java.awt.PrintJob.
    // In Java 1.2 we use java.awt.print.PrinterJob
    PrinterJob job = PrinterJob.getPrinterJob();

    // Alter the default page settings to request landscape mode
    PageFormat page = job.defaultPage();
    page.setOrientation(PageFormat.LANDSCAPE); // landscape by default

    // Tell the PrinterJob what Printable object we want to print.
    // PrintableComponent is defined as an inner class below
    String title = "Julia set for c={" + cx + "," + cy + "}";
    Printable printable = new PrintableComponent(this, title);
    job.setPrintable(printable, page);//from w  w w  . j a  va 2  s  .  c om

    // Call the printDialog() method to give the user a chance to alter
    // the printing attributes or to cancel the printing request.
    if (job.printDialog()) {
        // If we get here, then the user did not cancel the print job
        // So start printing, displaying a dialog for errors.
        try {
            job.print();
        } catch (PrinterException e) {
            JOptionPane.showMessageDialog(this, e.toString(), "PrinterException", JOptionPane.ERROR_MESSAGE);
        }
    }
}