Example usage for javax.swing JOptionPane NO_OPTION

List of usage examples for javax.swing JOptionPane NO_OPTION

Introduction

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

Prototype

int NO_OPTION

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

Click Source Link

Document

Return value from class method if NO is chosen.

Usage

From source file:Main.java

private static boolean isYesOrNo(int returnCode) {
    return (returnCode == JOptionPane.YES_OPTION) || (returnCode == JOptionPane.NO_OPTION);
}

From source file:Main.java

public static boolean confirmAction(Component comp, String title, String msg) {
    int decision = JOptionPane.showConfirmDialog(comp, msg, title, JOptionPane.YES_NO_OPTION,
            JOptionPane.WARNING_MESSAGE);
    if (decision == JOptionPane.NO_OPTION) {
        return false;
    }/*ww  w  . j a v a2s. c  om*/
    return true;
}

From source file:Main.java

public static boolean confirmOverwrite(Component comp, File file) {
    if (file.exists()) {
        int decision = JOptionPane.showConfirmDialog(comp, file.getName() + " exists. Overwrite?",
                "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
        if (decision == JOptionPane.NO_OPTION) {
            return false;
        }//from   w  w w. j  a  v a  2  s  .  c  o  m
    }
    return true;
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().add(new JLabel("Placeholder label"));
    pack();/* w w w .  ja  v  a2 s.  c om*/
    setSize(200, 200);
    setVisible(true);

    int replaced = JOptionPane.showConfirmDialog(this, "Replace existing selection?");

    String result = "?";
    switch (replaced) {
    case JOptionPane.CANCEL_OPTION:
        result = "Canceled";
        break;
    case JOptionPane.CLOSED_OPTION:
        result = "Closed";
        break;
    case JOptionPane.NO_OPTION:
        result = "No";
        break;
    case JOptionPane.YES_OPTION:
        result = "Yes";
        break;
    default:
        ;
    }
    System.out.println("Replace? " + result);
}

From source file:Test.java

public Test() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().add(new JLabel("Placeholder label"));
    pack();//from  w ww . java  2  s.c o m
    setSize(200, 200);
    setVisible(true);

    int replaced = JOptionPane.showConfirmDialog(this, "Replace existing selection?");

    String result = "?";
    switch (replaced) {
    case JOptionPane.CANCEL_OPTION:
        result = "Canceled";
        break;
    case JOptionPane.CLOSED_OPTION:
        result = "Closed";
        break;
    case JOptionPane.NO_OPTION:
        result = "No";
        break;
    case JOptionPane.YES_OPTION:
        result = "Yes";
        break;
    default:
        ;
    }
    System.out.println("Replace? " + result);
}

From source file:Main.java

public Main() throws HeadlessException {
    setSize(200, 200);// www .ja  v a 2  s. c o m
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton button1 = new JButton("Message dialog");
    button1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog((Component) e.getSource(), "Thank you!");
        }
    });

    JButton button2 = new JButton("Input dialog");
    button2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String text = JOptionPane.showInputDialog((Component) e.getSource(), "What is your name?");
            if (text != null && !text.equals("")) {
                JOptionPane.showMessageDialog((Component) e.getSource(), "Hello " + text);
            }
        }
    });

    JButton button3 = new JButton("Yes no dialog");
    button3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int result = JOptionPane.showConfirmDialog((Component) e.getSource(), "Close this application?");
            if (result == JOptionPane.YES_OPTION) {
                System.exit(0);
            } else if (result == JOptionPane.NO_OPTION) {
                System.out.println("Do nothing");
            }
        }
    });

    setLayout(new FlowLayout(FlowLayout.CENTER));
    getContentPane().add(button1);
    getContentPane().add(button2);
    getContentPane().add(button3);
}

From source file:net.sf.nmedit.nordmodular.NmFileService.java

public static NMPatch openPatch(File file, File sourceFile, final String title, boolean showExceptionDialog) {
    NMContextData data = NMContextData.sharedInstance();

    try {//from w  w  w .  j a  va 2  s. c  o m
        boolean setFilePointerToNull = false;
        if (isFileAlreadyOpen(file)) {
            if (JOptionPane.showConfirmDialog(Nomad.sharedInstance().getWindow().getRootPane(),
                    "File \"" + file + "\" is already open.\nDo you want to open a copy of the file?",
                    "Open...", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
                Nomad.sharedInstance().setSelectedDocumentByFile(file);
                return null;
            }

            setFilePointerToNull = true;
        }

        NMPatch patch = NMPatch.createPatchFromFile(file);
        patch.setEditSupportEnabled(false);

        if (title != null)
            patch.setName(title);

        final PatchDocument pd = createPatchDoc(patch);

        if (setFilePointerToNull) {
            if (sourceFile != null) {
                String name = sourceFile.getName();
                if (name.toLowerCase().endsWith(".pch"))
                    name = name.substring(0, name.length() - 4);
                patch.setName(name);
            }
        } else {
            if (sourceFile != null) {
                patch.setProperty("file", sourceFile);
                pd.setURI(sourceFile);
            }
        }

        patch.setEditSupportEnabled(true);
        patch.setModified(false);
        DocumentManager dm = Nomad.sharedInstance().getDocumentManager();
        dm.add(pd);
        dm.setSelection(pd);

        return patch;

    } catch (Exception e) {
        Log log = LogFactory.getLog(NmFileService.class);
        if (log.isWarnEnabled()) {
            log.warn("open failed: " + file, e);
        }
        if (showExceptionDialog) {
            ExceptionDialog.showErrorDialog(Nomad.sharedInstance().getWindow().getRootPane(),
                    "Could not open file '" + file + "' (" + e.getMessage() + ")", "Could not open file", e);
        }
    }

    return null;
}

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

public static void run(final PmsConfiguration configuration) {
    // Total number of questions
    int numberOfQuestions = Platform.isMac() ? 4 : 5;

    // The current question number
    int currentQuestionNumber = 1;

    String status = new StringBuilder().append(Messages.getString("Wizard.2")).append(" %d ")
            .append(Messages.getString("Wizard.4")).append(" ").append(numberOfQuestions).toString();

    Object[] okOptions = { Messages.getString("Dialog.OK") };

    Object[] yesNoOptions = { Messages.getString("Dialog.YES"), Messages.getString("Dialog.NO") };

    Object[] networkTypeOptions = { Messages.getString("Wizard.8"), Messages.getString("Wizard.9"),
            Messages.getString("Wizard.10") };

    if (!Platform.isMac()) {
        // Ask if they want UMS to start minimized
        int whetherToStartMinimized = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.3"),
                String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[1]);

        if (whetherToStartMinimized == JOptionPane.YES_OPTION) {
            configuration.setMinimized(true);
        } else if (whetherToStartMinimized == JOptionPane.NO_OPTION) {
            configuration.setMinimized(false);
        }/*from   w w  w. j  a v a  2s.co  m*/
    }

    // Ask if their network is wired, etc.
    int networkType = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.7"),
            String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, networkTypeOptions, networkTypeOptions[1]);

    switch (networkType) {
    case JOptionPane.YES_OPTION:
        // Wired (Gigabit)
        configuration.setMaximumBitrate("0");
        configuration.setMPEG2MainSettings("Automatic (Wired)");
        configuration.setx264ConstantRateFactor("Automatic (Wired)");
        break;
    case JOptionPane.NO_OPTION:
        // Wired (100 Megabit)
        configuration.setMaximumBitrate("90");
        configuration.setMPEG2MainSettings("Automatic (Wired)");
        configuration.setx264ConstantRateFactor("Automatic (Wired)");
        break;
    case JOptionPane.CANCEL_OPTION:
        // Wireless
        configuration.setMaximumBitrate("30");
        configuration.setMPEG2MainSettings("Automatic (Wireless)");
        configuration.setx264ConstantRateFactor("Automatic (Wireless)");
        break;
    default:
        break;
    }

    // Ask if they want to hide advanced options
    int whetherToHideAdvancedOptions = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.11"),
            String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[0]);

    if (whetherToHideAdvancedOptions == JOptionPane.YES_OPTION) {
        configuration.setHideAdvancedOptions(true);
    } else if (whetherToHideAdvancedOptions == JOptionPane.NO_OPTION) {
        configuration.setHideAdvancedOptions(false);
    }

    // Ask if they want to scan shared folders
    int whetherToScanSharedFolders = JOptionPane.showOptionDialog(null,
            Messages.getString("Wizard.IsStartupScan"), String.format(status, currentQuestionNumber++),
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[0]);

    if (whetherToScanSharedFolders == JOptionPane.YES_OPTION) {
        configuration.setScanSharedFoldersOnStartup(true);
    } else if (whetherToScanSharedFolders == JOptionPane.NO_OPTION) {
        configuration.setScanSharedFoldersOnStartup(false);
    }

    // Ask to set at least one shared folder
    JOptionPane.showOptionDialog(null, Messages.getString("Wizard.12"),
            String.format(status, currentQuestionNumber++), JOptionPane.OK_OPTION,
            JOptionPane.INFORMATION_MESSAGE, null, okOptions, okOptions[0]);

    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                JFileChooser chooser;
                try {
                    chooser = new JFileChooser();
                } catch (Exception ee) {
                    chooser = new JFileChooser(new RestrictedFileSystemView());
                }

                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                chooser.setDialogTitle(Messages.getString("Wizard.12"));
                chooser.setMultiSelectionEnabled(false);
                if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
                    configuration.setOnlySharedDirectory(chooser.getSelectedFile().getAbsolutePath());
                } else {
                    // If the user cancels this option, the default directories will be used.
                }
            }
        });
    } catch (InterruptedException | InvocationTargetException e) {
        LOGGER.error("Error when saving folders: ", e);
    }

    // The wizard finished, do not ask them again
    configuration.setRunWizard(false);

    // Save all changes
    try {
        configuration.save();
    } catch (ConfigurationException e) {
        LOGGER.error("Error when saving changed configuration: ", e);
    }
}

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/*from  w  w w  .j  ava2s  .  c  om*/
        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:com.sec.ose.osi.ui.ApplicationCloseMgr.java

synchronized public void exit() {

    log.debug("exit() - identifyQueueSize: " + IdentifyQueue.getInstance().size());

    ComponentAPIWrapper.save();/*from  www  .ja  v a  2 s .  c o m*/

    if (IdentifyQueue.getInstance().size() <= 0) {

        CacheableMgr.getInstance().saveToCache();

        UserRequestHandler.getInstance().handle(UserRequestHandler.DELETE_IDENTIFICATION_TABLE, null, true, // progress
                false // result
        );

        log.debug("OSIT EXIT...");
        System.exit(0);
    }

    log.debug("show message dialog to confirm exit or not");

    String[] buttonList = { "Yes", "No" };
    int choice = JOptionPane.showOptionDialog(null,
            "Identification Queue is not empty.(size : " + IdentifyQueue.getInstance().size() + ")\n"
                    + "If you close this application with non-empty queue.\n"
                    + "identification process for this queue will start again.\n"
                    + "But it's not recommended. (Data loss problem)\n" + "Do you really want to exit now?\n",
            "Exit", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, buttonList, "Yes");
    if (choice == JOptionPane.NO_OPTION) {
        return; // will not exit. 
    }

    log.debug("user select yes option and create thread");

    JDlgExitMessage dlgExitMessage = new JDlgExitMessage();
    String message = "OSI try to sync with Protex Server.\n" + "It takes several minutes to finish.";
    DialogDisplayerThread aDialogDiaplayerThread = new DialogDisplayerThread(message, dlgExitMessage);
    CompleteSendingThread aCompleteSendingThread = new CompleteSendingThread(aDialogDiaplayerThread);

    log.debug("Thread start");

    aDialogDiaplayerThread.execute();

    aCompleteSendingThread.start();

    dlgExitMessage.setVisible(true); // block

    CacheableMgr.getInstance().saveToCache();

    log.debug("OSIT EXIT...");
    System.exit(0);
}