Example usage for javax.swing JOptionPane showConfirmDialog

List of usage examples for javax.swing JOptionPane showConfirmDialog

Introduction

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

Prototype

public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType,
        int messageType) throws HeadlessException 

Source Link

Document

Brings up a dialog where the number of choices is determined by the optionType parameter, where the messageType parameter determines the icon to display.

Usage

From source file:de.huxhorn.lilith.swing.preferences.PreferencesDialog.java

public void reinitializeDetailsViewFiles() {
    String dialogTitle = "Reinitialize details view files?";
    String message = "This resets all details view related files, all manual changes will be lost!\nReinitialize details view right now?";
    int result = JOptionPane.showConfirmDialog(this, message, dialogTitle, JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE);
    // TODO: add "Show in Finder/Explorer" button if running on Mac/Windows
    if (JOptionPane.OK_OPTION != result) {
        return;//  w  ww.j  a v a 2 s. c o  m
    }

    applicationPreferences.initDetailsViewRoot(true);
}

From source file:io.heming.accountbook.ui.MainFrame.java

private void deleteRecord() {
    int selectedRow = table.getSelectedRow();
    if (selectedRow < 0) {
        JOptionPane.showMessageDialog(MainFrame.this, "", "",
                JOptionPane.ERROR_MESSAGE);
        return;//from  w  ww  .jav a 2 s  .c  o m
    }
    Record record = model.getRecord(table.convertRowIndexToModel(selectedRow));
    System.out.println(record);
    if (JOptionPane.showConfirmDialog(MainFrame.this,
            String.format("??%d?", record.getId()), "",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
        try {
            recordFacade.delete(record);
            searchRecords();
        } catch (Exception e1) {
            e1.printStackTrace();
            JOptionPane.showMessageDialog(MainFrame.this, e1.getMessage(), "", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:serial.ChartFromSerial.java

private void connect_jBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connect_jBtnActionPerformed
    defaultSeries.clear();/* w  w w  .  j a  va  2  s . c  om*/
    text.setText("");
    if ("Connect".equals(connect_jBtn.getText())) {

        //Attempt to connect to to serial port
        chosenPort = SerialPort.getCommPort(portList_jCombo.getSelectedItem().toString());
        chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
        chosenPort.setBaudRate(Integer.parseInt(baudRate_jCombo.getSelectedItem().toString()));

        if (chosenPort.openPort()) {
            createSerialThread(chosenPort);
            buttonsConnected();
            //                if(createSerialThread(chosenPort)){
            //                    buttonsConnected();
            //                } else {
            //                    JOptionPane.showMessageDialog(rootPane, "Failed to create a serial connection.", "Serial connection failed.", JOptionPane.ERROR_MESSAGE);
            //                    chosenPort.closePort();
            //                }
        } else {
            if (JOptionPane.showConfirmDialog(rootPane,
                    "Error at " + portList_jCombo.getSelectedItem().toString() + "\nWould you like to refresh?",
                    "Trouble connecting to " + portList_jCombo.getSelectedItem().toString(),
                    JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) == JOptionPane.YES_OPTION) {
                hardRefresh();
            } else {
                buttonsOff();
            }
        }
    } else {
        //Attempt to disconnect from the serial port
        chosenPort.closePort();
        softRefresh();
        samples = 0;

    }
}

From source file:com.intuit.tank.tools.debugger.ActionProducer.java

/**
 * // w  w w . j  a  va 2 s  .  co  m
 * @return
 */
public Action getSelectTankAction() {
    Action ret = actionMap.get(ACTION_SELECT_TANK);
    if (ret == null) {
        ret = new AbstractAction(ACTION_SELECT_TANK) {
            private static final long serialVersionUID = 1L;
            final JComboBox cb = getComboBox();

            @Override
            public void actionPerformed(ActionEvent event) {
                try {
                    int selected = JOptionPane.showConfirmDialog(debuggerFrame, cb,
                            "Enter the base URL to Tank:", JOptionPane.OK_CANCEL_OPTION,
                            JOptionPane.QUESTION_MESSAGE);
                    if (selected == JOptionPane.OK_OPTION) {
                        String url = (String) cb.getSelectedItem();
                        if (url != null) {
                            int startInd = url.indexOf('(');
                            int endInd = url.indexOf(')');
                            if (startInd != -1 && endInd != -1) {
                                url = url.substring(startInd + 1, endInd);
                            }
                            url = StringUtils.removeEndIgnoreCase(url, "/");
                            if (!url.startsWith("http")) {
                                url = "http://" + url;
                            }
                            try {
                                new ScriptServiceClient(url).ping();
                                setServiceUrl(url);
                            } catch (Exception e) {
                                showError("Cannot connect to Tank at the url " + url
                                        + ". \nExample: http://tank.mysite.com/");
                            }
                        }
                    }
                } catch (HeadlessException e) {
                    showError("Error opening file: " + e);
                }
            }
        };
        ret.putValue(Action.SHORT_DESCRIPTION, "Enter a Tank URL.");
        actionMap.put(ACTION_SELECT_TANK, ret);
    }
    return ret;
}

From source file:de.huxhorn.lilith.swing.preferences.PreferencesDialog.java

public void reinitializeGroovyConditions() {
    String dialogTitle = "Reinitialize example groovy conditions?";
    String message = "This overwrites all example groovy conditions. Other conditions are not changed!\nReinitialize example groovy conditions right now?";
    int result = JOptionPane.showConfirmDialog(this, message, dialogTitle, JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE);
    // TODO: add "Show in Finder/Explorer" button if running on Mac/Windows
    if (JOptionPane.OK_OPTION != result) {
        return;/*from  w w  w .  j  a v  a  2s .c  o  m*/
    }

    applicationPreferences.installExampleConditions();
}

From source file:edu.ku.brc.helpers.EMailHelper.java

/**
 * Asks for a username and password./*from w  w w . j a v  a 2s  .co m*/
 * @param topframe the parent frame
 * @return the list of user[index 1] and password[index 2], or 'null' if cancel was pressed
 */
public static ArrayList<String> askForUserAndPassword(final Frame topframe) {
    ArrayList<String> userAndPass = new ArrayList<String>();
    //get remote prefs
    AppPreferences remotePrefs = AppPreferences.getRemote();
    //get remote password
    String remoteUsername = remotePrefs.get("settings.email.username", null); //$NON-NLS-1$

    PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p", "p,2px,p,2px,p")); //$NON-NLS-1$ //$NON-NLS-2$
    CellConstraints cc = new CellConstraints();
    JLabel plabel = createI18NFormLabel("EMailHelper.PASSWORD"); //$NON-NLS-1$ //$NON-NLS-2$
    JLabel ulabel = createI18NFormLabel("EMailHelper.USERNAME"); //$NON-NLS-1$ //$NON-NLS-2$
    JPasswordField passField = createPasswordField(25);
    JTextField userField = createTextField(remoteUsername, 25);
    JCheckBox savePassword = createCheckBox(getResourceString("EMailHelper.SAVE_PASSWORD")); //$NON-NLS-1$

    builder.add(ulabel, cc.xy(1, 1));
    builder.add(userField, cc.xy(3, 1));
    builder.add(plabel, cc.xy(1, 3));
    builder.add(passField, cc.xy(3, 3));
    builder.add(savePassword, cc.xy(3, 5));

    Integer option = JOptionPane.showConfirmDialog(topframe, builder.getPanel(),
            getResourceString("EMailHelper.PASSWORD_TITLE"), JOptionPane.OK_CANCEL_OPTION, //$NON-NLS-1$
            JOptionPane.QUESTION_MESSAGE);

    String passwordText = new String(passField.getPassword());
    String userText = new String(userField.getText());

    if (savePassword.isSelected()) {

        if (StringUtils.isNotEmpty(passwordText)) {
            remotePrefs.put("settings.email.password", Encryption.encrypt(passwordText)); //$NON-NLS-1$
        }
    }

    if (option == JOptionPane.CANCEL_OPTION) {
        return null;
    } //else

    userAndPass.add(0, userText);
    userAndPass.add(1, passwordText);
    return userAndPass;
}

From source file:com.qawaa.gui.EventWebScanGUI.java

/**
 * ???/*ww w . j a v a 2 s .c  om*/
 */
private void windowsClosed() {
    if (RUNNING) {
        int response = JOptionPane.showConfirmDialog(null,
                CONTEXT.getMessage("gobal.quit.dialog.msg", null, Locale.CHINA),
                CONTEXT.getMessage("gobal.quit.dialog.title", null, Locale.CHINA), JOptionPane.YES_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (response == JOptionPane.YES_OPTION) {
            System.exit(0);
        }
    } else {
        System.exit(0);
    }
}

From source file:com.qawaa.gui.PointAnalysisGUI.java

/**
 * ?//from w  ww  .j a  v  a 2  s  .c om
 * @param evt
 * @throws InterruptedException 
 */
private static void submitActionPerformed(ActionEvent evt) throws InterruptedException {
    EventDailyPointAnalysisThread edpaThread = EventDailyPointAnalysisThread.Instance();
    EventHourlyPointAnalysisThread ehpaThread = EventHourlyPointAnalysisThread.Instance();
    EventRealTimePointAnalysisThread erpaThread = EventRealTimePointAnalysisThread.Instance();
    if (RUNNING) {
        JOptionPane.showConfirmDialog(null, CONTEXT.getMessage("gobal.stop.dialog.msg", null, Locale.CHINA),
                CONTEXT.getMessage("gobal.stop.dialog.title", null, Locale.CHINA), JOptionPane.CLOSED_OPTION,
                JOptionPane.CLOSED_OPTION);
        return;
    }
    submit.setText(CONTEXT.getMessage("gobal.gui.button.init", null, Locale.CHINA));
    submit.setEnabled(false);
    LOG.info(CONTEXT.getMessage("gobal.db.connect", null, Locale.CHINA));
    Thread.sleep(1000L);
    WebScanControl c = WebScanControl.getInstance();
    try {
        if (!HibernateDataBaseCheck.check()) {
            LOG.error(CONTEXT.getMessage("gobal.db.connect.fail", null, Locale.CHINA));
            submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
            submit.setEnabled(true);
            return;
        }
    } catch (Exception e) {
        LOG.error(CONTEXT.getMessage("gobal.db.connect.fail", null, Locale.CHINA));
        submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
        submit.setEnabled(true);
        return;
    }
    LOG.info(CONTEXT.getMessage("gobal.db.connect.success", null, Locale.CHINA));
    Thread.sleep(500L);
    LOG.info(CONTEXT.getMessage("point.event.check", null, Locale.CHINA));
    if (c.isExistEventList()) {
        LOG.error(CONTEXT.getMessage("point.event.null", null, Locale.CHINA));
        submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
        submit.setEnabled(true);
        return;
    } else {
        LOG.info(CONTEXT.getMessage("point.event.check.success", null, Locale.CHINA));
    }
    LOG.info(CONTEXT.getMessage("point.start", null, Locale.CHINA));
    Thread.sleep(1000L);
    submit.setText(CONTEXT.getMessage("gobal.gui.button.stop", null, Locale.CHINA));
    submit.setEnabled(true);
    RUNNING = true;
    RunTimeListener runTimeListener = new RunTimeListener(runtime_value);
    runTimeListener.start();
    edpaThread.start();
    ehpaThread.start();
    erpaThread.start();
}

From source file:serial.ChartFromSerial.java

private void pause_jBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pause_jBtnActionPerformed
    if ("Play".equals(pause_jBtn.getText())) {
        while (!chosenPort.openPort()) {
            if (JOptionPane.showConfirmDialog(rootPane,
                    "Error at " + portList_jCombo.getSelectedItem().toString() + "\nWould you like to refresh?",
                    "Trouble connecting to " + portList_jCombo.getSelectedItem().toString(),
                    JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) == JOptionPane.NO_OPTION) {
                buttonsOff();//from  w w  w .  ja  va  2  s .  c om
                return;
            } else {
                portNames = SerialPort.getCommPorts();
                if (portNames.length > 0) {
                    if (portNames.length >= 1) {
                        Object[] possibilities = new Object[portNames.length];
                        for (int i = 0; i < portNames.length; i++) {
                            possibilities[i] = portNames[i].getSystemPortName();
                        }
                        String s = (String) JOptionPane.showInputDialog(rootPane,
                                "Other ports are available.\nSelect one to continue on that port or cancel to disconnect.",
                                "Another port is available", JOptionPane.PLAIN_MESSAGE, null, possibilities,
                                null);
                        chosenPort.closePort();
                        if (s != null) {
                            chosenPort = SerialPort.getCommPort(s);
                            chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
                            chosenPort.setBaudRate(
                                    Integer.parseInt(baudRate_jCombo.getSelectedItem().toString()));
                            softRefresh();
                            portList_jCombo.setSelectedItem(s);
                            if (chosenPort.openPort()) {
                                createSerialThread(chosenPort);
                                pause_jBtn.setText("Pause");
                                connect_jBtn.setEnabled(true);
                                return;
                            }
                        } else {
                            buttonsOff();
                            return;
                        }
                    } else {
                        if (JOptionPane.showConfirmDialog(rootPane,
                                portNames[0].getSystemPortName()
                                        + " is available. Would you like to use it instead?",
                                "Another port is available",
                                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                            chosenPort.closePort();
                            chosenPort = SerialPort.getCommPort(portNames[0].getSystemPortName());
                            chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
                            chosenPort.setBaudRate(
                                    Integer.parseInt(baudRate_jCombo.getSelectedItem().toString()));
                            softRefresh();
                            portList_jCombo.setSelectedItem(portNames[0].getSystemPortName());
                            if (chosenPort.openPort()) {
                                createSerialThread(chosenPort);
                                pause_jBtn.setText("Pause");
                                connect_jBtn.setEnabled(true);
                                return;
                            }
                        } else {
                            buttonsOff();
                            return;
                        }
                    }
                } else {
                    JOptionPane.showMessageDialog(rootPane, "You are currently not connected to any devices.",
                            "No devices found", JOptionPane.INFORMATION_MESSAGE);
                    softRefresh();
                    buttonsOff();
                    return;
                }
            }

        }
        createSerialThread(chosenPort);
        pause_jBtn.setText("Pause");
    } else {
        chosenPort.closePort();
        pause_jBtn.setText("Play");
    }
}

From source file:com.qawaa.gui.EventWebScanGUI.java

/**
 * ?/*from   w  ww  .j  a  va  2s  .c om*/
 * @param evt
 * @throws InterruptedException 
 */
private static void submitActionPerformed(ActionEvent evt) throws InterruptedException {
    WebSearchScanThread wssThread = WebSearchScanThread.Instance();
    if (RUNNING) {
        wssThread.threadStop();
        JOptionPane.showConfirmDialog(null, CONTEXT.getMessage("gobal.stop.dialog.msg", null, Locale.CHINA),
                CONTEXT.getMessage("gobal.stop.dialog.title", null, Locale.CHINA), JOptionPane.CLOSED_OPTION,
                JOptionPane.CLOSED_OPTION);
        return;
    }
    submit.setText(CONTEXT.getMessage("gobal.gui.button.init", null, Locale.CHINA));
    submit.setEnabled(false);
    LOG.info(CONTEXT.getMessage("gobal.db.connect", null, Locale.CHINA));
    Thread.sleep(1000L);
    WebScanControl c = WebScanControl.getInstance();
    try {
        if (!HibernateDataBaseCheck.check()) {
            LOG.error(CONTEXT.getMessage("gobal.db.connect.fail", null, Locale.CHINA));
            submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
            submit.setEnabled(true);
            return;
        }
    } catch (Exception e) {
        LOG.error(CONTEXT.getMessage("gobal.db.connect.fail", null, Locale.CHINA));
        submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
        submit.setEnabled(true);
        return;
    }
    LOG.info(CONTEXT.getMessage("gobal.db.connect.success", null, Locale.CHINA));
    Thread.sleep(500L);
    LOG.info(CONTEXT.getMessage("event.web.scan.event.check", null, Locale.CHINA));
    if (c.isExistEventList()) {
        LOG.error(CONTEXT.getMessage("event.web.scan.event.null", null, Locale.CHINA));
        submit.setText(CONTEXT.getMessage("gobal.gui.button.run", null, Locale.CHINA));
        submit.setEnabled(true);
        return;
    } else {
        LOG.info(CONTEXT.getMessage("event.web.scan.event.check.success", null, Locale.CHINA));
    }
    LOG.info(CONTEXT.getMessage("event.web.scan.start", null, Locale.CHINA));
    Thread.sleep(1000L);
    submit.setText(CONTEXT.getMessage("gobal.gui.button.stop", null, Locale.CHINA));
    submit.setEnabled(true);
    RUNNING = true;
    RunTimeListener runTimeListener = new RunTimeListener(runtime_value);
    runTimeListener.start();
    wssThread.start();
}