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:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java

public static DialogResult showConfirmationDialog(Component parent, String title, String message) {

    final Object[] options = { "Yes", "No", "Cancel" };
    final int outcome = JOptionPane.showOptionDialog(parent, message, title, JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
    switch (outcome) {
    case 0:/*w  w  w  .  j  a  va2 s .c  om*/
        return DialogResult.YES;
    case 1:
        return DialogResult.NO;
    case 2:
    case JOptionPane.CLOSED_OPTION:
        return DialogResult.CANCEL;
    default:
        throw new RuntimeException("Internal error, unexpected outcome " + outcome);
    }
}

From source file:be.fedict.eid.tsl.Pkcs11CallbackHandler.java

private char[] getPin() {
    Box mainPanel = Box.createVerticalBox();

    Box passwordPanel = Box.createHorizontalBox();
    JLabel promptLabel = new JLabel("eID PIN:");
    passwordPanel.add(promptLabel);/* www  .  j  av a 2 s. co m*/
    passwordPanel.add(Box.createHorizontalStrut(5));
    JPasswordField passwordField = new JPasswordField(8);
    passwordPanel.add(passwordField);
    mainPanel.add(passwordPanel);

    Component parentComponent = null;
    int result = JOptionPane.showOptionDialog(parentComponent, mainPanel, "eID PIN?",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
    if (result == JOptionPane.OK_OPTION) {
        char[] pin = passwordField.getPassword();
        return pin;
    }
    throw new RuntimeException("operation canceled.");
}

From source file:com.pdk.DisassembleElfAction.java

@Override
public void actionPerformed(ActionEvent e) {
    try {//w ww  . j a  v a2  s  .c o  m
        Lookup context = Utilities.actionsGlobalContext();
        DataObject file = context.lookup(DataObject.class);
        if (file == null) {
            showList();
        } else {
            File fileObj = new File(file.getPrimaryFile().getPath());
            if (!fileObj.getName().endsWith(".o")) {
                showList();
            } else {
                File dir = new File(file.getFolder().getPrimaryFile().getPath());
                Object[] options = { "Disasm", "Sections", "Cancel" };
                int n = JOptionPane.showOptionDialog(null, "Please select", "Question",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
                        options[2]);

                if (n == 2) {
                    return;
                }

                String command2 = null;
                if (n == 0) {
                    command2 = "i586-peter-elf-objdump -S";
                } else if (n == 1) {
                    command2 = "i586-peter-elf-readelf -S";
                }
                if (command2 == null) {
                    return;
                }
                final String command = "/toolchain/bin/" + command2 + " " + fileObj.getName();

                process = Runtime.getRuntime().exec(command, null, dir);
                InputStreamReader isr = new InputStreamReader(process.getInputStream());
                final BufferedReader br = new BufferedReader(isr, 1024 * 1024 * 50);
                final JProgressBarDialog d = new JProgressBarDialog(new JFrame(),
                        "i586-peter-elf-objdump -S " + fileObj.getName(), true);

                d.progressBar.setIndeterminate(true);
                d.progressBar.setStringPainted(true);
                d.progressBar.setString("Updating");
                d.addCancelEventListener(this);
                Thread longRunningThread = new Thread() {
                    public void run() {
                        try {
                            lines = new StringBuilder();
                            String line;
                            stop = false;
                            while (!stop && (line = br.readLine()) != null) {
                                d.progressBar.setString(line);
                                lines.append(line).append("\n");
                            }
                            DisassembleDialog disassembleDialog = new DisassembleDialog();
                            disassembleDialog.setTitle(command);
                            if (((DefaultComboBoxModel) disassembleDialog.enhancedTextArea1.fontComboBox
                                    .getModel()).getIndexOf("Monospaced") != -1) {
                                disassembleDialog.enhancedTextArea1.fontComboBox.setSelectedItem("Monospaced");
                            }
                            if (((DefaultComboBoxModel) disassembleDialog.enhancedTextArea1.fontComboBox
                                    .getModel()).getIndexOf("Monospaced.plain") != -1) {
                                disassembleDialog.enhancedTextArea1.fontComboBox
                                        .setSelectedItem("Monospaced.plain");
                            }
                            disassembleDialog.enhancedTextArea1.setText(lines.toString());
                            disassembleDialog.setVisible(true);
                        } catch (Exception ex) {
                            ModuleLib.log(CommonLib.printException(ex));
                        }
                    }
                };
                d.thread = longRunningThread;
                d.setVisible(true);
            }
        }
    } catch (Exception ex) {
        ModuleLib.log(CommonLib.printException(ex));
    }
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopComponentsHelper.java

public static int convertMessageType(Frame.MessageMode messageType) {
    switch (messageType) {
    case CONFIRMATION:
    case CONFIRMATION_HTML:
        return JOptionPane.QUESTION_MESSAGE;
    case WARNING:
    case WARNING_HTML:
        return JOptionPane.WARNING_MESSAGE;
    default://from   w w w .j  av  a2s.  c  o  m
        return JOptionPane.INFORMATION_MESSAGE;
    }
}

From source file:net.itransformers.topologyviewer.menu.handlers.graphTools.shortherstPathMenuHandlers.DijkstraWeightedShortestPathMenuHandler.java

@Override
public void actionPerformed(ActionEvent e) {
    final GraphViewerPanel viewerPanel = (GraphViewerPanel) frame.getTabbedPane().getSelectedComponent();
    final MyVisualizationViewer vv = (MyVisualizationViewer) viewerPanel.getVisualizationViewer();

    Collection<String> vertices = viewerPanel.getCurrentGraph().getVertices();
    String[] test = vertices.toArray(new String[0]);
    Arrays.sort(test);//w w  w .  j a v  a2  s  .  co  m

    final String mFrom = (String) JOptionPane.showInputDialog(frame, "Choose A Node", "A Node",
            JOptionPane.PLAIN_MESSAGE, null, test, test[0]);
    final String mTo = (String) JOptionPane.showInputDialog(frame, "Choose B Node", "B Node",
            JOptionPane.PLAIN_MESSAGE, null, test, test[0]);
    String weightedKey = JOptionPane.showInputDialog(frame, "Enter Weighted Key", "Weighted Key",
            JOptionPane.QUESTION_MESSAGE);

    Transformer<String, Double> wtTransformer = new Transformer<String, Double>() {
        public Double transform(String edgeId) {

            return null;
        }
    };

    final Graph<String, String> mGraph = viewerPanel.getCurrentGraph();
    DijkstraShortestPath<String, String> alg = new DijkstraShortestPath(mGraph, wtTransformer);

    final List<String> mPred = alg.getPath(mFrom, mTo);
    //        System.out.println("The shortest unweighted path from" + mFrom +" to " + mTo + " is:");
    //        System.out.println(mPred.toString());

    if (mPred == null) {
        JOptionPane.showMessageDialog(frame,
                String.format("Shortest path between %s,%s is not found", mFrom, mTo), "Message",
                JOptionPane.INFORMATION_MESSAGE);
        return;
    }

    final Layout<String, String> layout = vv.getGraphLayout();
    for (final String edge : layout.getGraph().getEdges()) {
        if (mPred.contains(edge)) {
            vv.setEdgeStroke(edge, new BasicStroke(4f));

        }

    }
}

From source file:com.sec.ose.osi.ui.ApplicationCloseMgr.java

synchronized public void exit() {

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

    ComponentAPIWrapper.save();// w  w  w.j  a 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);
}

From source file:io.github.jeremgamer.editor.panels.Actions.java

public Actions(final JFrame frame, final ActionPanel ap) {
    this.frame = frame;

    this.setBorder(BorderFactory.createTitledBorder(""));
    JButton add = null;//from w w  w .  java2  s.com
    try {
        add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                JOptionPane jop = new JOptionPane();
                @SuppressWarnings("static-access")
                String name = jop.showInputDialog(null, "Nommez l'action :", "Crer une action",
                        JOptionPane.QUESTION_MESSAGE);

                if (name != null) {
                    for (int i = 0; i < data.getSize(); i++) {
                        if (data.get(i).equals(name)) {
                            name += "1";
                        }
                    }
                    data.addElement(name);
                    new ActionSave(name);
                    OtherPanel.updateLists();
                    ButtonPanel.updateLists();
                    ActionPanel.updateLists();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    });

    JButton remove = null;
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                if (actionList.getSelectedValue() != null) {
                    File file = new File("projects/" + Editor.getProjectName() + "/actions/"
                            + actionList.getSelectedValue() + ".rbd");
                    JOptionPane jop = new JOptionPane();
                    @SuppressWarnings("static-access")
                    int option = jop.showConfirmDialog(null,
                            "tes-vous sr de vouloir supprimer cette action?", "Avertissement",
                            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                    if (option == JOptionPane.OK_OPTION) {
                        if (actionList.getSelectedValue().equals(ap.getFileName())) {
                            ap.setFileName("");
                        }
                        ap.hide();
                        file.delete();
                        data.remove(actionList.getSelectedIndex());
                        OtherPanel.updateLists();
                        ButtonPanel.updateLists();
                    }
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }

        }

    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS));
    buttons.add(add);
    buttons.add(remove);

    updateList();
    actionList.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("unchecked")
        public void mouseClicked(MouseEvent evt) {
            JList<String> list = (JList<String>) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    ap.show();
                    ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            ap.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            ap.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        ap.hide();
                        list.clearSelection();
                    }
                }
            } else if (evt.getClickCount() == 3) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    ap.show();
                    ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            ap.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            ap.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            ap.load(new File("projects/" + Editor.getProjectName() + "/actions/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        ap.hide();
                        list.clearSelection();
                    }
                }
            }
        }
    });
    JScrollPane listPane = new JScrollPane(actionList);
    listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(buttons);
    this.add(listPane);
    OtherPanel.updateLists();
}

From source file:components.CustomDialog.java

/** Creates the reusable dialog. */
public CustomDialog(Frame aFrame, String aWord, DialogDemo parent) {
    super(aFrame, true);
    dd = parent;//w  ww .  j  av  a  2s. c  o  m

    magicWord = aWord.toUpperCase();
    setTitle("Quiz");

    textField = new JTextField(10);

    //Create an array of the text and components to be displayed.
    String msgString1 = "What was Dr. SEUSS's real last name?";
    String msgString2 = "(The answer is \"" + magicWord + "\".)";
    Object[] array = { msgString1, msgString2, textField };

    //Create an array specifying the number of dialog buttons
    //and their text.
    Object[] options = { btnString1, btnString2 };

    //Create the JOptionPane.
    optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options,
            options[0]);

    //Make this dialog display it.
    setContentPane(optionPane);

    //Handle window closing correctly.
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            /*
             * Instead of directly closing the window,
             * we're going to change the JOptionPane's
             * value property.
             */
            optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION));
        }
    });

    //Ensure the text field always gets the first focus.
    addComponentListener(new ComponentAdapter() {
        public void componentShown(ComponentEvent ce) {
            textField.requestFocusInWindow();
        }
    });

    //Register an event handler that puts the text into the option pane.
    textField.addActionListener(this);

    //Register an event handler that reacts to option pane state changes.
    optionPane.addPropertyChangeListener(this);
}

From source file:io.github.jeremgamer.editor.panels.Buttons.java

public Buttons(final JFrame frame, final ButtonPanel be, final PanelSave ps) {
    this.setBorder(BorderFactory.createTitledBorder(""));

    this.frame = frame;

    JButton add = null;//from  w w w . j ava 2 s  .c o  m
    try {
        add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                JOptionPane jop = new JOptionPane();
                @SuppressWarnings("static-access")
                String name = jop.showInputDialog(null, "Nommez le bouton :", "Crer un bouton",
                        JOptionPane.QUESTION_MESSAGE);

                if (name != null) {
                    for (int i = 0; i < data.getSize(); i++) {
                        if (data.get(i).equals(name)) {
                            name += "1";
                        }
                    }
                    data.addElement(name);
                    new ButtonSave(name);
                    ActionPanel.updateLists();
                    OtherPanel.updateLists();
                    PanelsPanel.updateLists();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    });

    JButton remove = null;
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                if (buttonList.getSelectedValue() != null) {
                    File file = new File("projects/" + Editor.getProjectName() + "/buttons/"
                            + buttonList.getSelectedValue() + "/" + buttonList.getSelectedValue() + ".rbd");
                    JOptionPane jop = new JOptionPane();
                    @SuppressWarnings("static-access")
                    int option = jop.showConfirmDialog(null, "tes-vous sr de vouloir supprimer ce bouton?",
                            "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                    if (option == JOptionPane.OK_OPTION) {
                        File dir = new File("projects/" + Editor.getProjectName() + "/panels");
                        for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE,
                                TrueFileFilter.INSTANCE)) {
                            if (!f.isDirectory()) {
                                try {
                                    ps.load(f);
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                for (String section : ps
                                        .getSectionsContaining(buttonList.getSelectedValue() + " (Bouton)")) {
                                    ps.removeSection(section);
                                    try {
                                        ps.save(f);
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }
                        if (buttonList.getSelectedValue().equals(be.getFileName())) {
                            be.setFileName("");
                        }
                        be.hide();
                        file.delete();
                        File parent = new File(file.getParent());
                        for (File img : FileUtils.listFiles(parent, TrueFileFilter.INSTANCE,
                                TrueFileFilter.INSTANCE)) {
                            img.delete();
                        }
                        parent.delete();
                        data.remove(buttonList.getSelectedIndex());
                        ActionPanel.updateLists();
                        OtherPanel.updateLists();
                        PanelsPanel.updateLists();
                    }
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }

        }

    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS));
    buttons.add(add);
    buttons.add(remove);

    updateList();
    buttonList.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("unchecked")
        public void mouseClicked(MouseEvent evt) {
            JList<String> list = (JList<String>) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    be.load(new File("projects/" + Editor.getProjectName() + "/buttons/"
                            + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index)
                            + ".rbd"));
                    be.show();
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            be.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            be.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            be.load(new File("projects/" + Editor.getProjectName() + "/buttons/"
                                    + list.getModel().getElementAt(index) + "/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        be.hide();
                        list.clearSelection();
                    }
                }
            } else if (evt.getClickCount() == 3) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    be.load(new File("projects/" + Editor.getProjectName() + "/buttons/"
                            + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index)
                            + ".rbd"));
                    be.show();
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            be.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            be.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            be.load(new File("projects/" + Editor.getProjectName() + "/buttons/"
                                    + list.getModel().getElementAt(index) + "/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        be.hide();
                        list.clearSelection();
                    }
                }
            }
        }
    });
    JScrollPane listPane = new JScrollPane(buttonList);
    listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(buttons);
    this.add(listPane);

}

From source file:de.atomfrede.tools.evalutation.util.DialogUtil.java

public void showPlotTypeSelection() {
    SwingUtilities.invokeLater(new Runnable() {

        @Override//from  w w  w .  jav  a  2s. c  om
        public void run() {
            Object[] types = PlotType.values();

            PlotType selectedType = (PlotType) JOptionPane.showInputDialog(frame,
                    "Select type of plot you want to create.", "Select Plot Type", JOptionPane.QUESTION_MESSAGE,
                    Icons.IC_INFORMATION_LARGE, types, types[0]);

            if (selectedType != null) {
                log.debug("Plot " + selectedType + " should be created.");
                switch (selectedType) {
                case SIMPLE: {
                    SimplePlotWizard wizard = new SimplePlotWizard();
                    // wizard.setSize(600, 800);
                    wizard.setSize(wizard.getPreferredSize());
                    wizard.setLocationRelativeTo(frame);
                    wizard.setModal(true);
                    showWizardDialog(wizard);
                    break;
                }
                case TIME: {
                    TimePlotWizard wizard = new TimePlotWizard();
                    // wizard.setSize(600, 800);
                    wizard.setSize(wizard.getPreferredSize());
                    wizard.setLocationRelativeTo(frame);
                    wizard.setModal(true);
                    showWizardDialog(wizard);
                    break;
                }
                default:
                    break;
                }
            }
        }
    });
}