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:de.tntinteractive.portalsammler.gui.MainDialog.java

private void changePassword() throws GeneralSecurityException, IOException {
    final SecureRandom srand = new SecureRandom();
    final byte[] key = CryptoHelper.generateKey(srand);
    this.gui.showGeneratedPassword(CryptoHelper.keyToString(key));

    while (true) {
        final String enteredPw = this.gui.askForPassword(this.getStore().getDirectory());
        if (enteredPw == null) {
            //Abbruch durch den Benutzer
            return;
        }//  w w  w .  j a va  2  s  .  c o m
        if (Arrays.equals(key, CryptoHelper.keyFromString(enteredPw))) {
            //alles OK => ndern kann abgeschlossen werden
            break;
        }
        JOptionPane.showMessageDialog(this, "Das neue Passwort wurde nicht korrekt eingegeben.",
                "Falsches Passwort", JOptionPane.ERROR_MESSAGE, null);
    }

    this.table.setStore(this.getStore().recrypt(key));
}

From source file:me.philnate.textmanager.windows.MainWindow.java

/**
 * Initialize the contents of the frame.
 *//*from w  w  w.j  av  a  2 s.  co  m*/
private void initialize() {
    changeListener = new ChangeListener();

    frame = new JFrame();
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            Starter.shutdown();
        }
    });
    frame.setBounds(100, 100, 1197, 500);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new MigLayout("", "[grow]", "[][grow][::16px]"));

    customers = new CustomerComboBox();
    customers.addItemListener(changeListener);

    frame.getContentPane().add(customers, "flowx,cell 0 0,growx");

    jScrollPane = new JScrollPane();
    billLines = new BillingItemTable(frame, true);

    jScrollPane.setViewportView(billLines);
    frame.getContentPane().add(jScrollPane, "cell 0 1,grow");

    // for each file added through drag&drop create a new lineItem
    new FileDrop(jScrollPane, new FileDrop.Listener() {

        @Override
        public void filesDropped(File[] files) {
            for (File file : files) {
                addNewBillingItem(Document.loadAndSave(file));
            }
        }
    });

    monthChooser = new JMonthChooser();
    monthChooser.addPropertyChangeListener(changeListener);
    frame.getContentPane().add(monthChooser, "cell 0 0");

    yearChooser = new JYearChooser();
    yearChooser.addPropertyChangeListener(changeListener);
    frame.getContentPane().add(yearChooser, "cell 0 0");

    JButton btnAddLine = new JButton();
    btnAddLine.setIcon(ImageRegistry.getImage("load.gif"));
    btnAddLine.setToolTipText(getCaption("mw.tooltip.add"));
    btnAddLine.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            addNewBillingItem();
        }
    });

    frame.getContentPane().add(btnAddLine, "cell 0 0");

    JButton btnMassAdd = new JButton();
    btnMassAdd.setIcon(ImageRegistry.getImage("load_all.gif"));
    btnMassAdd.setToolTipText(getCaption("mw.tooltip.massAdd"));
    btnMassAdd.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser file = new DocXFileChooser();
            switch (file.showOpenDialog(frame)) {
            case JFileChooser.APPROVE_OPTION:
                File[] files = file.getSelectedFiles();
                if (null != files) {
                    for (File fl : files) {
                        addNewBillingItem(Document.loadAndSave(fl));
                    }
                }
                break;
            default:
                return;
            }
        }
    });

    frame.getContentPane().add(btnMassAdd, "cell 0 0");

    billNo = new JTextField();
    // enable/disable build button based upon text in billNo
    billNo.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent arg0) {
            setButtonStates();
        }

        @Override
        public void insertUpdate(DocumentEvent arg0) {
            setButtonStates();
        }

        @Override
        public void changedUpdate(DocumentEvent arg0) {
            setButtonStates();
        }

        private void setButtonStates() {
            boolean notBlank = StringUtils.isNotBlank(billNo.getText());
            build.setEnabled(notBlank);
            view.setEnabled(pdf.find(billNo.getText() + ".pdf").size() == 1);
        }
    });
    frame.getContentPane().add(billNo, "cell 0 0");
    billNo.setColumns(10);

    build = new JButton();
    build.setEnabled(false);// disable build Button until there's some
    // billNo entered
    build.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            if (runningThread == null) {
                try {
                    // check that billNo isn't empty or already used within
                    // another Bill
                    if (billNo.getText().trim().equals("")) {
                        JOptionPane.showMessageDialog(frame, getCaption("mw.dialog.error.billNoBlank.msg"),
                                getCaption("mw.dialog.error.billNoBlank.title"), JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                    try {
                        bill.setBillNo(billNo.getText()).save();
                    } catch (DuplicateKey e) {
                        // unset the internal value as this is already used
                        bill.setBillNo("");
                        JOptionPane.showMessageDialog(frame,
                                format(getCaption("mw.error.billNoUsed.msg"), billNo.getText()),
                                getCaption("mw.dialog.error.billNoBlank.title"), JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                    PDFCreator pdf = new PDFCreator(bill);
                    pdf.addListener(new ThreadCompleteListener() {

                        @Override
                        public void threadCompleted(NotifyingThread notifyingThread) {
                            build.setToolTipText(getCaption("mw.tooltip.build"));
                            build.setIcon(ImageRegistry.getImage("build.png"));
                            runningThread = null;
                            view.setEnabled(DB.pdf.find(billNo.getText() + ".pdf").size() == 1);
                        }
                    });
                    runningThread = new Thread(pdf);
                    runningThread.start();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                build.setToolTipText(getCaption("mw.tooltip.build.cancel"));
                build.setIcon(ImageRegistry.getImage("cancel.gif"));
            } else {
                runningThread.interrupt();
                runningThread = null;
                build.setToolTipText(getCaption("mw.tooltip.build"));
                build.setIcon(ImageRegistry.getImage("build.png"));

            }
        }
    });
    build.setToolTipText(getCaption("mw.tooltip.build"));
    build.setIcon(ImageRegistry.getImage("build.png"));
    frame.getContentPane().add(build, "cell 0 0");

    view = new JButton();
    view.setToolTipText(getCaption("mw.tooltip.view"));
    view.setIcon(ImageRegistry.getImage("view.gif"));
    view.setEnabled(false);
    view.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            File file = new File(System.getProperty("user.dir"),
                    format("template/%s.tmp.pdf", billNo.getText()));
            try {
                pdf.findOne(billNo.getText() + ".pdf").writeTo(file);
                new ProcessBuilder(Setting.find("pdfViewer").getValue(), file.getAbsolutePath()).start()
                        .waitFor();
                file.delete();
            } catch (IOException | InterruptedException e1) {
                // TODO Auto-generated catch block
                LOG.warn("Error while building PDF", e1);
            }
        }
    });
    frame.getContentPane().add(view, "cell 0 0");

    statusBar = new JPanel();
    statusBar.setBorder(new BevelBorder(BevelBorder.LOWERED));
    statusBar.setLayout(new BoxLayout(statusBar, BoxLayout.X_AXIS));
    GitRepositoryState state = DB.state;
    JLabel statusLabel = new JLabel(String.format("textManager Version v%s build %s",
            state.getCommitIdDescribe(), state.getBuildTime()));
    statusLabel.setHorizontalAlignment(SwingConstants.LEFT);
    statusBar.add(statusLabel);
    frame.add(statusBar, "cell 0 2,growx");

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    JMenu menu = new JMenu(getCaption("mw.menu.edit"));
    JMenuItem itemCust = new JMenuItem(getCaption("mw.menu.edit.customer"));
    itemCust.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            new CustomerWindow(customers);
        }
    });
    menu.add(itemCust);

    JMenuItem itemSetting = new JMenuItem(getCaption("mw.menu.edit.settings"));
    itemSetting.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            new SettingWindow();
        }
    });
    menu.add(itemSetting);

    JMenuItem itemImport = new JMenuItem(getCaption("mw.menu.edit.import"));
    itemImport.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            new ImportWindow(new ImportListener() {

                @Override
                public void entriesImported(List<BillingItem> items) {
                    for (BillingItem item : items) {
                        item.setCustomerId(customers.getSelectedCustomer().getId())
                                .setMonth(monthChooser.getMonth()).setYear(yearChooser.getYear());
                        item.save();
                        billLines.addRow(item);
                    }
                }
            }, frame);
        }
    });
    menu.add(itemImport);

    menuBar.add(menu);

    customers.loadCustomer();
    fillTableModel();
}

From source file:BRHInit.java

public void selectVPS(int idx) {
    try {/*  w  w  w  .j a va  2  s  . c o  m*/
        int id = vps_list.getJSONArray(idx).getInt(0);

        // call get_vnc_key
        JSONArray params = new JSONArray();
        params.put(id);

        JSONObject response = json_rpc("get_vnc_key", params);
        //System.out.println(response.toString());

        // set up the last of the parameters
        v.mainArgs[6] = "id";
        v.mainArgs[7] = Integer.toString(id);

        v.mainArgs[8] = "key";
        v.mainArgs[9] = response.getString("result");

        // start VNC
        v.init();
        v.start();
    } catch (Exception e) {
        System.err.println(e);

        JOptionPane.showMessageDialog(null, "Connection failed", "Connection failed",
                JOptionPane.ERROR_MESSAGE);

        showLoginPrompt();
    }
}

From source file:com.iucosoft.eavertizare.gui.SendAvertizareManualJDialog.java

private void jButtonSendAvertizareActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSendAvertizareActionPerformed
    String mesaj = "";
    int contor = 0;
    SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy");
    String mesajClient = jTextAreaMesaj.getText().replaceFirst("nume", client.getNume())
            .replaceFirst("prenume", client.getPrenume())
            .replaceFirst("data", sdf.format(client.getDateExpirare()).toString())
            .replaceFirst("compania", client.getFirma().getNumeFirma());
    switch (varianta) {
    case "SMS AND E-MAIL":
        mesaj = "Sms si e-mail";
        try {//from   w  ww  .  ja v  a2  s.  co  m
            mailSender.sendMail(client.getEmail(), "E-avertizare", mesajClient);
            smsSender.sendSms(client.getNrTelefon(), mesajClient);
        } catch (Exception ex) {
            //Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(new JFrame(), "Verificai conexiunea la internet!\n" + ex, "Error",
                    JOptionPane.ERROR_MESSAGE);
            contor = 1;
        }
        client.setTrimis(true);
        clientsDao.update(client.getFirma(), client);
        parent.refreshFrame();
        break;

    case "SMS":
        mesaj = "Sms";
        try {
            smsSender.sendSms(client.getNrTelefon(), mesajClient);
        } catch (Exception ex) {
            //Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(new JFrame(), "Verificai conexiunea la internet!\n" + ex, "Error",
                    JOptionPane.ERROR_MESSAGE);
            contor = 1;
        }
        break;

    case "E-MAIL":
        mesaj = "E-mail";
        try {
            mailSender.sendMail(client.getEmail(), "E-avertizare", mesajClient);
        } catch (Exception ex) {
            //Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(new JFrame(), "Verificai conexiunea la internet!\n" + ex, "Error",
                    JOptionPane.ERROR_MESSAGE);
            contor = 1;
        }
        break;
    }

    this.dispose();

    if (contor != 1) {
        JOptionPane.showMessageDialog(parent, mesaj + " transmis cu succes!", "Info",
                JOptionPane.INFORMATION_MESSAGE);
    }

}

From source file:net.rptools.maptool.client.MapTool.java

/**
 * Displays the messages provided as <code>messages</code> by calling
 * {@link #showMessage(Object[], String, int, Object...)} and passing
 * <code>"msg.title.messageDialogFeedback"</code> and
 * <code>JOptionPane.ERROR_MESSAGE</code> as parameters.
 * // w w  w. j ava  2s .c  o  m
 * @param messages
 *            the Objects (normally strings) to put in the body of the
 *            dialog; no properties file lookup is performed!
 */
public static void showFeedback(Object[] messages) {
    showMessage(messages, "msg.title.messageDialogFeedback", JOptionPane.ERROR_MESSAGE);
}

From source file:de.rub.nds.burp.espresso.gui.UIOptions.java

/**
 * Save all configurations in the UI to the system.
 * @param path The path to the place where the configuration file should be stored.
 *///from w  w  w  .  j a  v a2s  .  c om
private void saveConfig(String path) {
    File file = new File(path);
    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "Can not create the config file.", "Can not create file.",
                    JOptionPane.ERROR_MESSAGE);
            Logging.getInstance().log(getClass(), ex);
        } catch (Exception ex) {
            Logging.getInstance().log(getClass(), ex);
        }
    }
    if (!file.isDirectory() && file.canWrite() && file.canRead()) {

        JSONObject config_obj = new JSONObject();
        config_obj.put("SSOActive", activeSSOProtocols.isSelected());
        config_obj.put("OpenIDActive", openID1.isSelected());
        config_obj.put("OpenIDConnectActive", openIDConnect1.isSelected());
        config_obj.put("OAuthActive", oAuth.isSelected());
        config_obj.put("FacebookConnectActive", facebookConnect.isSelected());
        config_obj.put("BrowserIDActive", browserID1.isSelected());
        config_obj.put("SAMLActive", saml1.isSelected());
        config_obj.put("MicrosoftAccountActive", msAccount.isSelected());

        config_obj.put("HighlightActive", highlightBool);

        config_obj.put("Schema", schemaText1.getText());
        config_obj.put("Certificate", certText1.getText());
        config_obj.put("Private Key", privKeyText1.getText());
        config_obj.put("Public Key", pubKeyText1.getText());

        config_obj.put("Input Script", scriptInText1.getText());
        config_obj.put("Output Script", scriptOutText1.getText());

        config_obj.put("Libraries", libText1.getText());

        config_obj.put("Config", path);

        config_obj.put("LogLvl", LoggingLevel);

        try {
            FileWriter fw = new FileWriter(file);
            try {
                fw.write(config_obj.toJSONString());
                //                    JOptionPane.showMessageDialog(this,
                //                                "The config is now saved.",
                //                                "Saved successfully.",
                //                                JOptionPane.INFORMATION_MESSAGE);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this,
                        "The config file can not be written!\n\nError:\n" + ex.toString(),
                        "Can not write in config file", JOptionPane.ERROR_MESSAGE);
                Logging.getInstance().log(getClass(), ex);
            } finally {
                fw.flush();
                fw.close();
            }
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "Can not open the config file!\n\nError:\n" + ex.toString(),
                    "Can not open config file", JOptionPane.ERROR_MESSAGE);
            Logging.getInstance().log(getClass(), ex);
        } catch (Exception ex) {
            Logging.getInstance().log(getClass(), ex);
        }

    } else {
        JOptionPane.showMessageDialog(this, "The file:\n" + path + "\n is not readable/writable.",
                "File not Found!", JOptionPane.ERROR_MESSAGE);
        Logging.getInstance().log(getClass(), "The file:" + path + " is not readable/writable.", Logging.ERROR);
    }
}

From source file:it.ferogrammer.ui.MainAppFrame.java

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    if (jPanel2.getComponentCount() == 1 && (jPanel2.getComponent(0) instanceof ElectropherogramChartPanel)) {
        ElectropherogramChartPanel chartPanel = (ElectropherogramChartPanel) jPanel2.getComponent(0);
        final JFileChooser fc = new JFileChooser();
        //            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fc.showSaveDialog(chartPanel);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            if (!file.getName().endsWith(".png")) {
                int extindex = file.getPath().indexOf('.') == -1 ? file.getPath().length()
                        : file.getPath().indexOf('.');
                file = new File(file.getPath().substring(0, extindex) + ".png");
            }//from   w  w w.j  av a 2s  . com
            try {
                ChartUtilities.saveChartAsPNG(file, chartPanel.getChart(), chartPanel.getWidth(),
                        chartPanel.getHeight());
            } catch (IOException ex) {
                JOptionPane op = new JOptionPane();
                op.showMessageDialog(jPanel2, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    } else {
        JOptionPane op = new JOptionPane();
        op.showMessageDialog(jPanel2, "Cannot export image", "Error", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:Data.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset.//from   w  ww . j  ava2 s  . c o m
 * @throws ClassNotFoundException 
 */
private static XYDataset createDataset(Statement stmt) throws ClassNotFoundException {

    TimeSeries s1 = new TimeSeries("Humidit");
    TimeSeries s2 = new TimeSeries("Temprature");
    ResultSet rs = null;

    try {
        String sqlRequest = "SELECT * FROM `t_temphum`";
        rs = stmt.executeQuery(sqlRequest);
        Double hum;
        Double temp;
        Timestamp date;

        while (rs.next()) {
            hum = rs.getDouble("tmp_humidity");
            temp = rs.getDouble("tmp_temperature");
            date = rs.getTimestamp("tmp_date");

            if (tempUnit == "F") {
                temp = celsiusToFahrenheit(temp.toString());
            }

            if (date != null) {
                s1.add(new Second(date), hum);
                s2.add(new Second(date), temp);
            } else {
                JOptionPane.showMessageDialog(panelPrincipal, "Il manque une date dans la dase de donne",
                        "Date null", JOptionPane.WARNING_MESSAGE);
            }
        }

        rs.close();
    } catch (SQLException e) {
        String exception = e.toString();

        if (e.getErrorCode() == 0) {
            JOptionPane.showMessageDialog(panelPrincipal,
                    "Le serveur met trop de temps  rpondre ! Veuillez rssayer plus tard ou contacter un administrateur",
                    "Connection timed out", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception,
                    "Titre : exception", JOptionPane.ERROR_MESSAGE);
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (Exception e) {
        String exception = e.toString();
        JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception, "Titre : exception",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
    }

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);
    dataset.addSeries(s2);

    return dataset;

}

From source file:com.emr.schemas.TableRelationsForm.java

/**
 * Method to populate a table's columns to a {@link ListModel}
 * @param tableName {@link String} Table name
 *//*from  w  w  w .  ja va2s .  co m*/
private void populateTableColumnsToList(String tableName) {
    try {
        DatabaseMetaData dbmd = emrConn.getMetaData();
        ResultSet rs = dbmd.getColumns(null, null, tableName, "%");
        while (rs.next()) {
            String colName = rs.getString(4);
            listModel.addElement(tableName + "." + colName);
        }
    } catch (SQLException e) {
        String stacktrace = org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e);
        JOptionPane.showMessageDialog(this,
                "Could not fetch Tables for the KenyaEMR Database. Error Details: " + stacktrace,
                "Table Names Error", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:mondrian.gui.Workbench.java

/**
 * save properties/*from ww w .  j a  v  a  2s  .  c  o m*/
 */
public void storeWorkbenchProperties() {
    // save properties to file
    File dir = new File(WORKBENCH_USER_HOME_DIR);
    try {
        if (dir.exists()) {
            if (!dir.isDirectory()) {
                JOptionPane.showMessageDialog(this, getResourceConverter().getFormattedString(
                        "workbench.user.home.not.directory",
                        "{0} is not a directory!\nPlease rename this file and retry to save configuration!",
                        WORKBENCH_USER_HOME_DIR), "", JOptionPane.ERROR_MESSAGE);
                return;
            }
        } else {
            dir.mkdirs();
        }
    } catch (Exception ex) {
        LOGGER.error("storeWorkbenchProperties: mkdirs", ex);
        JOptionPane.showMessageDialog(this,
                getResourceConverter().getFormattedString("workbench.user.home.exception",
                        "An error is occurred creating workbench configuration directory:\n{0}\nError is: {1}",
                        WORKBENCH_USER_HOME_DIR, ex.getLocalizedMessage()),
                "", JOptionPane.ERROR_MESSAGE);
        return;
    }

    OutputStream out = null;
    try {
        out = new FileOutputStream(new File(WORKBENCH_CONFIG_FILE));
        workbenchProperties.store(out, "Workbench configuration");
    } catch (Exception e) {
        LOGGER.error("storeWorkbenchProperties: store", e);
        JOptionPane.showMessageDialog(this,
                getResourceConverter().getFormattedString("workbench.save.configuration",
                        "An error is occurred creating workbench configuration file:\n{0}\nError is: {1}",
                        WORKBENCH_CONFIG_FILE, e.getLocalizedMessage()),
                "", JOptionPane.ERROR_MESSAGE);
    } finally {
        try {
            out.close();
        } catch (IOException eIO) {
            LOGGER.error("storeWorkbenchProperties: out.close", eIO);
        }
    }
}