Example usage for javax.swing JOptionPane QUESTION_MESSAGE

List of usage examples for javax.swing JOptionPane QUESTION_MESSAGE

Introduction

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

Prototype

int QUESTION_MESSAGE

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

Click Source Link

Document

Used for questions.

Usage

From source file:edu.ku.brc.af.prefs.PreferencesDlg.java

@Override
public boolean closePrefs() {
    if (okBtn.isEnabled()) {
        Object[] options = { getResourceString("PrefsDlg.SAVE_PREFS"), //$NON-NLS-1$
                getResourceString("PrefsDlg.DONT_SAVE_PREFS"), //$NON-NLS-1$
                getResourceString("CANCEL") //$NON-NLS-1$
        };/*from   w ww. j  a  v a  2  s.  c  o m*/
        int userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(),
                getResourceString("PrefsDlg.MSG"), //$NON-NLS-1$
                getResourceString("PREFERENCES"), //$NON-NLS-1$
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
        if (userChoice == JOptionPane.YES_OPTION) {
            okButtonPressed();

        } else if (userChoice == JOptionPane.NO_OPTION) {
            cancelButtonPressed();
        } else {
            return false;
        }
    } else {
        cancelButtonPressed();
    }
    return true;
}

From source file:DialogDemo.java

/** Creates the panel shown by the second tab. */
private JPanel createFeatureDialogBox() {
    final int numButtons = 5;
    JRadioButton[] radioButtons = new JRadioButton[numButtons];
    final ButtonGroup group = new ButtonGroup();

    JButton showItButton = null;//from  www . j a  va2  s .c o m

    final String pickOneCommand = "pickone";
    final String textEnteredCommand = "textfield";
    final String nonAutoCommand = "nonautooption";
    final String customOptionCommand = "customoption";
    final String nonModalCommand = "nonmodal";

    radioButtons[0] = new JRadioButton("Pick one of several choices");
    radioButtons[0].setActionCommand(pickOneCommand);

    radioButtons[1] = new JRadioButton("Enter some text");
    radioButtons[1].setActionCommand(textEnteredCommand);

    radioButtons[2] = new JRadioButton("Non-auto-closing dialog");
    radioButtons[2].setActionCommand(nonAutoCommand);

    radioButtons[3] = new JRadioButton("Input-validating dialog " + "(with custom message area)");
    radioButtons[3].setActionCommand(customOptionCommand);

    radioButtons[4] = new JRadioButton("Non-modal dialog");
    radioButtons[4].setActionCommand(nonModalCommand);

    for (int i = 0; i < numButtons; i++) {
        group.add(radioButtons[i]);
    }
    radioButtons[0].setSelected(true);

    showItButton = new JButton("Show it!");
    showItButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String command = group.getSelection().getActionCommand();

            // pick one of many
            if (command == pickOneCommand) {
                Object[] possibilities = { "ham", "spam", "yam" };
                String s = (String) JOptionPane.showInputDialog(frame,
                        "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog",
                        JOptionPane.PLAIN_MESSAGE, icon, possibilities, "ham");

                // If a string was returned, say so.
                if ((s != null) && (s.length() > 0)) {
                    setLabel("Green eggs and... " + s + "!");
                    return;
                }

                // If you're here, the return value was null/empty.
                setLabel("Come on, finish the sentence!");

                // text input
            } else if (command == textEnteredCommand) {
                String s = (String) JOptionPane.showInputDialog(frame,
                        "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog",
                        JOptionPane.PLAIN_MESSAGE, icon, null, "ham");

                // If a string was returned, say so.
                if ((s != null) && (s.length() > 0)) {
                    setLabel("Green eggs and... " + s + "!");
                    return;
                }

                // If you're here, the return value was null/empty.
                setLabel("Come on, finish the sentence!");

                // non-auto-closing dialog
            } else if (command == nonAutoCommand) {
                final JOptionPane optionPane = new JOptionPane(
                        "The only way to close this dialog is by\n" + "pressing one of the following buttons.\n"
                                + "Do you understand?",
                        JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);

                // You can't use pane.createDialog() because that
                // method sets up the JDialog with a property change
                // listener that automatically closes the window
                // when a button is clicked.
                final JDialog dialog = new JDialog(frame, "Click a button", true);
                dialog.setContentPane(optionPane);
                dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                dialog.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent we) {
                        setLabel("Thwarted user attempt to close window.");
                    }
                });
                optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent e) {
                        String prop = e.getPropertyName();

                        if (dialog.isVisible() && (e.getSource() == optionPane)
                                && (JOptionPane.VALUE_PROPERTY.equals(prop))) {
                            // If you were going to check something
                            // before closing the window, you'd do
                            // it here.
                            dialog.setVisible(false);
                        }
                    }
                });
                dialog.pack();
                dialog.setLocationRelativeTo(frame);
                dialog.setVisible(true);

                int value = ((Integer) optionPane.getValue()).intValue();
                if (value == JOptionPane.YES_OPTION) {
                    setLabel("Good.");
                } else if (value == JOptionPane.NO_OPTION) {
                    setLabel("Try using the window decorations " + "to close the non-auto-closing dialog. "
                            + "You can't!");
                } else {
                    setLabel("Window unavoidably closed (ESC?).");
                }

                // non-auto-closing dialog with custom message area
                // NOTE: if you don't intend to check the input,
                // then just use showInputDialog instead.
            } else if (command == customOptionCommand) {
                customDialog.setLocationRelativeTo(frame);
                customDialog.setVisible(true);

                String s = customDialog.getValidatedText();
                if (s != null) {
                    // The text is valid.
                    setLabel("Congratulations!  " + "You entered \"" + s + "\".");
                }

                // non-modal dialog
            } else if (command == nonModalCommand) {
                // Create the dialog.
                final JDialog dialog = new JDialog(frame, "A Non-Modal Dialog");

                // Add contents to it. It must have a close button,
                // since some L&Fs (notably Java/Metal) don't provide one
                // in the window decorations for dialogs.
                JLabel label = new JLabel("<html><p align=center>" + "This is a non-modal dialog.<br>"
                        + "You can have one or more of these up<br>" + "and still use the main window.");
                label.setHorizontalAlignment(JLabel.CENTER);
                Font font = label.getFont();
                label.setFont(label.getFont().deriveFont(font.PLAIN, 14.0f));

                JButton closeButton = new JButton("Close");
                closeButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        dialog.setVisible(false);
                        dialog.dispose();
                    }
                });
                JPanel closePanel = new JPanel();
                closePanel.setLayout(new BoxLayout(closePanel, BoxLayout.LINE_AXIS));
                closePanel.add(Box.createHorizontalGlue());
                closePanel.add(closeButton);
                closePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 5));

                JPanel contentPane = new JPanel(new BorderLayout());
                contentPane.add(label, BorderLayout.CENTER);
                contentPane.add(closePanel, BorderLayout.PAGE_END);
                contentPane.setOpaque(true);
                dialog.setContentPane(contentPane);

                // Show it.
                dialog.setSize(new Dimension(300, 150));
                dialog.setLocationRelativeTo(frame);
                dialog.setVisible(true);
            }
        }
    });

    return createPane(moreDialogDesc + ":", radioButtons, showItButton);
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private void addEmptyNode(final PhylogenyNode node) {
    if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) {
        errorMessageNoCutCopyPasteInUnrootedDisplay();
        return;/*from  w  w  w .j av  a2  s  .co  m*/
    }
    final String label = getASimpleTextRepresentationOfANode(node);
    String msg = "";
    if (ForesterUtil.isEmpty(label)) {
        msg = "How to add the new, empty node?";
    } else {
        msg = "How to add the new, empty node to node" + label + "?";
    }
    final Object[] options = { "As sibling", "As descendant", "Cancel" };
    final int r = JOptionPane.showOptionDialog(this, msg, "Addition of Empty New Node",
            JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
    boolean add_as_sibling = true;
    if (r == 1) {
        add_as_sibling = false;
    } else if (r != 0) {
        return;
    }
    final Phylogeny phy = new Phylogeny();
    phy.setRoot(new PhylogenyNode());
    phy.setRooted(true);
    if (add_as_sibling) {
        if (node.isRoot()) {
            JOptionPane.showMessageDialog(this, "Cannot add sibling to root", "Attempt to add sibling to root",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }
        phy.addAsSibling(node);
    } else {
        phy.addAsChild(node);
    }
    _phylogeny.externalNodesHaveChanged();
    _phylogeny.hashIDs();
    _phylogeny.recalculateNumberOfExternalDescendants(true);
    resetNodeIdToDistToLeafMap();
    setEdited(true);
    repaint();
}

From source file:com.jvms.i18neditor.editor.Editor.java

public void showFindTranslationDialog() {
    String key = Dialogs.showInputDialog(this, MessageBundle.get("dialogs.translation.find.title"),
            MessageBundle.get("dialogs.translation.find.text"), JOptionPane.QUESTION_MESSAGE);
    if (key != null) {
        TranslationTreeNode node = translationTree.getNodeByKey(key.trim());
        if (node == null) {
            Dialogs.showWarningDialog(this, MessageBundle.get("dialogs.translation.find.title"),
                    MessageBundle.get("dialogs.translation.find.error"));
        } else {//from w w  w .ja v  a  2  s  . com
            translationTree.setSelectionNode(node);
        }
    }
}

From source file:com.ejie.uda.jsonI18nEditor.Editor.java

public void showAddTranslationDialog() {
    String key = "";
    String newKey = "";
    TranslationTreeNode node = translationTree.getSelectedNode();
    if (node != null && !node.isRoot()) {
        key = node.getKey();//w  w w. ja va 2  s. co  m
    }
    while (newKey != null && newKey.isEmpty()) {
        newKey = (String) JOptionPane.showInputDialog(this, MessageBundle.get("dialogs.translation.add.text"),
                MessageBundle.get("dialogs.translation.add.title"), JOptionPane.QUESTION_MESSAGE, null, null,
                key);
        if (newKey != null) {
            newKey = newKey.trim();
            if (!TranslationKeys.isValid(newKey)) {
                showError(MessageBundle.get("dialogs.translation.add.error"));
            } else {
                addTranslationKey(newKey);
            }
        }
    }
}

From source file:gdt.jgui.entity.index.JIndexPanel.java

/**
 * Get the context menu.// w  ww.  ja v a2 s  .co m
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = new JMenu("Context");
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            //System.out.println("IndexPanel:getConextMenu:menu selected");
            menu.removeAll();
            JMenuItem expandItem = new JMenuItem("Expand");
            expandItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    expandAll(tree, new TreePath(rootNode), true);
                }
            });
            menu.add(expandItem);
            JMenuItem collapseItem = new JMenuItem("Collapse");
            collapseItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    expandAll(tree, new TreePath(rootNode), false);
                }
            });
            menu.add(collapseItem);
            final TreePath[] tpa = tree.getSelectionPaths();
            if (tpa != null && tpa.length > 0) {
                menu.addSeparator();
                JMenuItem copyItem = new JMenuItem("Copy");
                copyItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        cut = false;
                        console.clipboard.clear();
                        DefaultMutableTreeNode node;
                        String locator$;
                        for (TreePath tp : tpa) {
                            node = (DefaultMutableTreeNode) tp.getLastPathComponent();
                            locator$ = (String) node.getUserObject();
                            if (locator$ != null)
                                console.clipboard.putString(locator$);
                        }
                    }
                });
                menu.add(copyItem);
                JMenuItem cutItem = new JMenuItem("Cut");
                cutItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        cut = true;
                        console.clipboard.clear();
                        DefaultMutableTreeNode node;
                        String locator$;
                        for (TreePath tp : tpa) {
                            node = (DefaultMutableTreeNode) tp.getLastPathComponent();
                            locator$ = (String) node.getUserObject();
                            if (locator$ != null)
                                console.clipboard.putString(locator$);
                        }
                    }
                });
                menu.add(cutItem);
                JMenuItem deleteItem = new JMenuItem("Delete");
                deleteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?",
                                "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                        if (response == JOptionPane.YES_OPTION) {
                            try {
                                DefaultMutableTreeNode node;
                                String locator$;
                                String nodeKey$;
                                for (TreePath tp : tpa) {
                                    node = (DefaultMutableTreeNode) tp.getLastPathComponent();
                                    locator$ = (String) node.getUserObject();
                                    nodeKey$ = Locator.getProperty(locator$, NODE_KEY);
                                    index.removeElementItem("index.title", nodeKey$);
                                    index.removeElementItem("index.jlocator", nodeKey$);
                                }
                                Entigrator entigrator = console.getEntigrator(entihome$);
                                entigrator.save(index);
                                JConsoleHandler.execute(console, getLocator());
                            } catch (Exception ee) {
                                LOGGER.info(ee.toString());
                            }
                        }
                    }
                });
                menu.add(deleteItem);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });

    return menu;
}

From source file:UserInterface.FinanceRole.DonateToPoorPeopleJPanel.java

private void donateJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_donateJButtonActionPerformed

    //Validation//from  ww  w .  j  av a2 s .com
    boolean validationSuccess;
    validationSuccess = validation();

    if (validationSuccess) {

        Person objPPPerson = null;
        UserAccount objPPUserAccount = null;

        int selectedPP = poorPeopleJTable.getSelectedRow();

        if (selectedPP < 0) {
            JOptionPane.showMessageDialog(null, "Please select a Person");
            return;
        }

        objPPUserAccount = (UserAccount) poorPeopleJTable.getValueAt(selectedPP, 2);

        if (objPPUserAccount != null) {
            objPPPerson = objPPUserAccount.getObjPerson();

            objWorldEnterprise.getObjTransactionDirectory().updateTransactionAccount();

            BigDecimal worldBalance = objWorldEnterprise.getObjTransactionDirectory().getAvailableRealBalance();

            int positiveWorldBalance = worldBalance.compareTo(donationAmount);

            if (positiveWorldBalance >= 1) {

                int response = JOptionPane.showConfirmDialog(null,
                        "Total donation of $ " + donationAmount + "/- Do you want to Donate?", "Confirm",
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (response == JOptionPane.YES_OPTION) {

                    //PoorPeople Transaction
                    Transaction objVirtualPPTransaction = (Transaction) objPPPerson
                            .getObjPoorPeopleTransactionDirectory().addNewTransaction();
                    objVirtualPPTransaction
                            .setTransactionBDAmount(new BigDecimal(donationAmountJTextField.getText()));
                    objVirtualPPTransaction.setObjUserAccountSource(objUserAccount);
                    objVirtualPPTransaction.setObjUserAccountDestination(objPPUserAccount);
                    objVirtualPPTransaction.setTransactionSource(
                            Transaction.TransactionSourceType.FromWorldEnterprise.getValue());
                    objVirtualPPTransaction.setTransactionDestination(
                            Transaction.TransactionSourceType.ToPoorPeople.getValue());
                    objVirtualPPTransaction.setTransactionType(Transaction.TransactionType.Credit.getValue());
                    objVirtualPPTransaction
                            .setTransactionMode(Transaction.TransactionModeType.Virtual.getValue());
                    objPPPerson.getObjPoorPeopleTransactionDirectory().updateTransactionAccount();

                    //WorldEnterprise Transaction
                    Transaction objVirtualWETransaction = (Transaction) objWorldEnterprise
                            .getObjTransactionDirectory().addNewTransaction();
                    objVirtualWETransaction
                            .setTransactionBDAmount(new BigDecimal(donationAmountJTextField.getText()));
                    objVirtualWETransaction.setObjUserAccountSource(objUserAccount);
                    objVirtualWETransaction.setObjUserAccountDestination(objPPUserAccount);
                    objVirtualWETransaction.setTransactionSource(
                            Transaction.TransactionSourceType.FromWorldEnterprise.getValue());
                    objVirtualWETransaction.setTransactionDestination(
                            Transaction.TransactionSourceType.ToPoorPeople.getValue());
                    objVirtualWETransaction.setTransactionType(Transaction.TransactionType.Debit.getValue());
                    objVirtualWETransaction
                            .setTransactionMode(Transaction.TransactionModeType.Virtual.getValue());
                    objWorldEnterprise.getObjTransactionDirectory().updateTransactionAccount();

                    JOptionPane.showMessageDialog(null, "$ " + donationAmount + "/- donated successfully");

                    //DonationGivenRecords
                    String donationLogs = objVirtualWETransaction.getTransactionID() + ","
                            + objVirtualWETransaction.getTransactionBDAmount() + ","
                            + objVirtualWETransaction.getObjUserAccountSource() + ","
                            + objVirtualWETransaction.getTransactionSource() + ","
                            + objVirtualWETransaction.getObjUserAccountDestination() + ","
                            + objVirtualWETransaction.getTransactionDestination() + ","
                            + objVirtualWETransaction.getTransactionType() + ","
                            + objVirtualWETransaction.getTransactionMode();

                    GenerateReports.donationGivenRecords(donationLogs);

                    donationAmountJTextField.setText(null);

                    populateTransactionTable(objPPPerson);
                }
            } else {
                JOptionPane.showMessageDialog(null, "World Balance is low");
            }
        } else {
            JOptionPane.showMessageDialog(null, "Please select again");
        }
    }
}

From source file:com.ejie.uda.jsonI18nEditor.Editor.java

public void showFindTranslationDialog() {
    String key = (String) JOptionPane.showInputDialog(this, MessageBundle.get("dialogs.translation.find.text"),
            MessageBundle.get("dialogs.translation.find.title"), JOptionPane.QUESTION_MESSAGE);
    if (key != null) {
        TranslationTreeNode node = translationTree.getNodeByKey(key.trim());
        if (node == null) {
            showWarning(MessageBundle.get("dialogs.translation.find.title"),
                    MessageBundle.get("dialogs.translation.find.error"));
        } else {/*  w  w  w. ja v a  2 s  .  c  o  m*/
            translationTree.setSelectedNode(node);
        }
    }
}

From source file:de.mycrobase.jcloudapp.Main.java

private static Map<String, String> showLoginDialog() {
    String message = ""; //"Welcome to JCloudApp!";

    JTextField usernameField = new JTextField();
    JPasswordField passwordField = new JPasswordField();
    JCheckBox remeberCheck = new JCheckBox("Remember login (on disk)");
    remeberCheck.setSelected(true);/*  www.  j  a  va 2  s.c o  m*/
    Object[] content = { message, "Username:", usernameField, "Password:", passwordField, remeberCheck };

    //        int res = JOptionPane.showOptionDialog(
    //            null, content, "JCloudApp - Login",
    //            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, icon,
    //            null, usernameField);
    int res = JOptionPane.showConfirmDialog(null, content, "JCloudApp - Login", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, IconLarge);

    if (res == JOptionPane.OK_OPTION) {
        HashMap<String, String> m = new HashMap<String, String>();
        m.put("username", usernameField.getText());
        m.put("password", new String(passwordField.getPassword()));
        m.put("remember", Boolean.toString(remeberCheck.isSelected()));
        return m;
    } else {
        return null;
    }
}

From source file:gui.QTLResultsPanel.java

void runPerm() {
    Object[] values = { "Full Model", "Reduced Model" };
    Object selected = JOptionPane.showInputDialog(MsgBox.frm, "Please select which model to use:",
            "Select Model", JOptionPane.QUESTION_MESSAGE, null, values, values[0]);

    if (selected == null)
        return;// ww  w .  j  a  v a  2s  .  c om

    // Full model or reduced?
    boolean fullModel = selected == values[0];

    int cmLength = (int) order.getDistanceTotal();
    String tName = currentTrait.getName();

    PermDialog dialog = new PermDialog(MsgBox.frm, qtlResult.getTraitFile(), fullModel, tName, cmLength);
    if (dialog.isOK()) {
        PermResult result = dialog.getResult();
        currentTrait.setPermResult(result);

        displayTrait(currentTrait);
        AppFrameMenuBar.aFileSave.setEnabled(true);
    }

}