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)
        throws HeadlessException 

Source Link

Document

Brings up a dialog where the number of choices is determined by the optionType parameter.

Usage

From source file:rhinova.gui.dataentry.link.LinkDataEntryPanel.java

private void btnCreateActionPerformed(ActionEvent ev) {
    try {//w w  w.  j  a  v  a2s  . com
        // test if the Tableable object can be created
        linkList.createTableable(getUserInputArray());

        // ask for confirmation
        int response = JOptionPane.showConfirmDialog(null, "Do you wish to create this Componenet?", "Confirm?",
                JOptionPane.YES_NO_CANCEL_OPTION);
        if (response == 0) {
            // create the object
            linkList.createAndAddNewInstance(getUserInputArray());
            JOptionPane.showMessageDialog(null, "Model Component Created", "Success",
                    JOptionPane.INFORMATION_MESSAGE);
        }
        // report exceptions to the user
    } catch (IncorrectDataType e) {
        EntityExceptionDialogs.onIncorrectDataType(e.getMessage());
    } catch (ConstraintViolatedException e) {
        EntityExceptionDialogs.onConstraintViolateException(e.getMessage());
    } catch (NullInputException e) {
        EntityExceptionDialogs.onNullInputException(e.getMessage());
    }
}

From source file:de.erdesignerng.visual.MessagesHelper.java

public static boolean displayQuestionMessage(Component aParent, String aMessage, String aQuestionText,
        String aMessageKey, Object... aReplacementValues) {
    return JOptionPane.showConfirmDialog(aParent, StringEscapeUtils.unescapeJava(aMessage),
            StringEscapeUtils.unescapeJava(aQuestionText), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
}

From source file:rhinova.gui.dataentry.reserve.ReserveDataEntryPanel.java

private void btnCreateReserveActionPerformed(ActionEvent ev) {
    try {/*from   www . ja  v  a 2 s .com*/
        // test if the Tableable object can be created
        reserveList.createTableable(getUserInputArray());

        // ask for confirmation
        int response = JOptionPane.showConfirmDialog(null, "Do you wish to create this Componenet?", "Confirm?",
                JOptionPane.YES_NO_CANCEL_OPTION);
        if (response == 0) {
            // create the object
            reserveList.createAndAddNewInstance(getUserInputArray());
            JOptionPane.showMessageDialog(null, "Model Component Created", "Success",
                    JOptionPane.INFORMATION_MESSAGE);
        }
        // report exceptions to the user
    } catch (IncorrectDataType e) {
        EntityExceptionDialogs.onIncorrectDataType(e.getMessage());
    } catch (ConstraintViolatedException e) {
        EntityExceptionDialogs.onConstraintViolateException(e.getMessage());
    } catch (NullInputException e) {
        EntityExceptionDialogs.onNullInputException(e.getMessage());
    }
}

From source file:com.babynamesUI.java

protected void processWindowEvent(WindowEvent e) {

    if (e.getID() == WindowEvent.WINDOW_CLOSING) {

        //System.exit(0); //remove on release

        int exit = JOptionPane.showConfirmDialog(this, "Are you sure?", "Confirm Exit?",
                JOptionPane.YES_NO_OPTION);
        if (exit == JOptionPane.YES_OPTION) {
            System.exit(0);//from w w w .j a v a 2  s  .c om
        }

    } else {

        super.processWindowEvent(e);
    }
}

From source file:net.minder.KnoxWebHdfsJavaClientExamplesTest.java

@BeforeClass
public static void setupSuite() {
    Console console = System.console();
    if (console != null) {
        console.printf("Knox Host: ");
        KNOX_HOST = console.readLine();/*from   w w w.  j a  v a 2  s  .  c o m*/
        console.printf("Topology : ");
        TOPOLOGY_PATH = console.readLine();
        console.printf("Username : ");
        TEST_USERNAME = console.readLine();
        console.printf("Password: ");
        TEST_PASSWORD = new String(console.readPassword());
    } else {
        JLabel label = new JLabel("Enter Knox host, topology, username, password:");
        JTextField host = new JTextField(KNOX_HOST);
        JTextField topology = new JTextField(TOPOLOGY_PATH);
        JTextField username = new JTextField(TEST_USERNAME);
        JPasswordField password = new JPasswordField(TEST_PASSWORD);
        int choice = JOptionPane.showConfirmDialog(null,
                new Object[] { label, host, topology, username, password }, "Credentials",
                JOptionPane.OK_CANCEL_OPTION);
        assertThat(choice, is(JOptionPane.YES_OPTION));
        TEST_USERNAME = username.getText();
        TEST_PASSWORD = new String(password.getPassword());
        KNOX_HOST = host.getText();
        TOPOLOGY_PATH = topology.getText();
    }
    TOPOLOGY_URL = String.format("%s://%s:%d/%s/%s", KNOX_SCHEME, KNOX_HOST, KNOX_PORT, KNOX_PATH,
            TOPOLOGY_PATH);
    WEBHDFS_URL = String.format("%s/%s", TOPOLOGY_URL, WEBHDFS_PATH);
}

From source file:calendarexportplugin.exporter.CalExporter.java

public boolean exportPrograms(Program[] programs, CalendarExportSettings settings,
        AbstractPluginProgramFormating formatting) {
    mSavePath = getSavePath(settings);//from w w w  .jav  a2  s.  c om

    File file = chooseFile(programs);

    if (file == null) {
        return false;
    }

    if (file.exists()) {
        int result = JOptionPane.showConfirmDialog(CalendarExportPlugin.getInstance().getBestParentFrame(),
                mLocalizer.msg("overwriteMessage", "The File \n{0}\nalready exists. Overwrite it?",
                        file.getAbsolutePath()),
                mLocalizer.msg("overwriteTitle", "Overwrite?"), JOptionPane.YES_NO_OPTION);
        if (result != JOptionPane.YES_OPTION) {
            return false;
        }
    }

    mSavePath = file.getAbsolutePath();

    setSavePath(settings, mSavePath);
    export(file, programs, settings, formatting);

    return true;
}

From source file:org.keyboardplaying.xtt.ui.action.ConfirmClearPrefsAction.java

@Override
public void perform() throws ActionException {
    int confirm = JOptionPane.showConfirmDialog(null, i18nHelper.getMessage("warning.prefs.clear.close"),
            "Are you sure?", JOptionPane.YES_NO_OPTION);
    if (confirm == JOptionPane.YES_OPTION) {
        clearPrefsAction.perform();//from   w  ww  .j  a  v a  2s.c  om
        disposeAllWindows();
    }
}

From source file:net.menthor.editor.v2.util.Util.java

public static JFileChooser createChooser(String lastPath, final boolean checkOverrideFile) {
    return new JFileChooser(lastPath) {
        private static final long serialVersionUID = 1L;

        @Override/*  w ww  .ja v  a 2 s .  com*/
        public void approveSelection() {
            File f = getSelectedFile();
            if (f.exists() && checkOverrideFile) {
                int result = JOptionPane.showConfirmDialog(this,
                        "\"" + f.getName() + "\" already exists. Do you want to overwrite it?", "Existing file",
                        JOptionPane.YES_NO_CANCEL_OPTION);
                switch (result) {
                case JOptionPane.YES_OPTION:
                    super.approveSelection();
                    return;
                case JOptionPane.NO_OPTION:
                    return;
                case JOptionPane.CLOSED_OPTION:
                    return;
                case JOptionPane.CANCEL_OPTION:
                    cancelSelection();
                    return;
                }
            }
            super.approveSelection();
        }
    };
}

From source file:eu.apenet.dpt.standalone.gui.XsdAdderActionListener.java

public void actionPerformed(ActionEvent e) {
    JFileChooser xsdChooser = new JFileChooser();
    xsdChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    if (xsdChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
        File file = xsdChooser.getSelectedFile();
        if (isXSD(file)) {
            XsdInfoQueryComponent xsdInfoQueryComponent = new XsdInfoQueryComponent(labels, file.getName());

            int result = JOptionPane.showConfirmDialog(parent, xsdInfoQueryComponent, "title",
                    JOptionPane.OK_CANCEL_OPTION);
            if (result == JOptionPane.OK_OPTION) {
                if (StringUtils.isEmpty(xsdInfoQueryComponent.getName())) {
                    errorMessage();/*www .  ja v a2s . c o m*/
                } else {
                    if (saveXsd(file, xsdInfoQueryComponent.getName(), false,
                            xsdInfoQueryComponent.getXsdVersion(), xsdInfoQueryComponent.getFileType())) {
                        JRadioButton newButton = new JRadioButton(xsdInfoQueryComponent.getName());
                        newButton.addActionListener(new XsdSelectorListener(dataPreparationToolGUI));
                        dataPreparationToolGUI.getGroupXsd().add(newButton);
                        dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsdPanel(newButton);
                        dataPreparationToolGUI.getAPEPanel().getApeTabbedPane()
                                .addToXsdPanel(Box.createRigidArea(new Dimension(0, 10)));
                        JOptionPane.showMessageDialog(parent, labels.getString("xsdSaved") + ".",
                                labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon);
                    } else {
                        errorMessage();
                    }
                }
            }
        } else {
            errorMessage();
        }
    }
}

From source file:net.pms.newgui.Splash.java

@Override
public void mouseClicked(MouseEvent e) {
    int isShowSplashScreen = JOptionPane.showConfirmDialog(null, Messages.getString("Splash.1"),
            Messages.getString("Splash.2"), JOptionPane.YES_NO_OPTION);
    if (isShowSplashScreen == 0) {
        configuration.setShowSplashScreen(false);
        try {//from   www  . j  a  v  a  2s.co m
            configuration.save();
        } catch (ConfigurationException e1) {
            LOGGER.error("Error when saving the Splash Screen setting", e1);
        }
    }
}