Example usage for javax.swing JOptionPane OK_CANCEL_OPTION

List of usage examples for javax.swing JOptionPane OK_CANCEL_OPTION

Introduction

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

Prototype

int OK_CANCEL_OPTION

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

Click Source Link

Document

Type used for showConfirmDialog.

Usage

From source file:Main.java

/**
 * Mostra uma caixa de menssagem para que seja ensirido um valor.
 * @param frame// ww w  . j a  va 2 s .com
 * @param texto
 * @param title
 * @param valorInicial
 * @param type
 * @return
 * @author Thiago Benega
 * @since 13/04/2009
 */
public static String showTextboxDialog(javax.swing.JFrame frame, String texto, String title,
        String valorInicial, int type) {
    Object txt = null;
    JDialog jDialog = new JDialog();
    jDialog.setTitle(title);
    jDialog.setFocusableWindowState(true);

    if (frame != null) {
        frame.setExtendedState(Frame.ICONIFIED);
        frame.pack();
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    }

    switch (type) {
    case JOptionPane.OK_CANCEL_OPTION:
        txt = JOptionPane.showInputDialog(jDialog, texto, title, type, null, null, valorInicial);//.toString();
        break;
    case JOptionPane.YES_NO_OPTION:
        txt = JOptionPane.showConfirmDialog(jDialog, texto, title, type, JOptionPane.INFORMATION_MESSAGE);
        break;
    default:
        JOptionPane.showMessageDialog(jDialog, texto, title, type);
        break;
    }

    jDialog = null;
    return txt != null ? txt.toString() : null;

}

From source file:Main.java

public static int select(String[] selList, String msg) {
    JComboBox<String> box = new JComboBox<>(selList);
    Object msgs[] = new Object[2];
    msgs[0] = msg;//from w w w  . j a v  a2s .c om
    msgs[1] = box;
    int result = JOptionPane.showOptionDialog(null, msgs, msg, JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, null, null);
    if (result == JOptionPane.CANCEL_OPTION)
        return -1;
    return box.getSelectedIndex();
}

From source file:Main.java

/**
 * visualizzazione messaggio HTML/*from w  w w. j a  v a2 s . c  o m*/
 *
 * @param pFrame frame di provenienza (di solito e' <code>this</code>).
 * @param pTask task di provenienza del messaggio (di solito e'
 * <code>TASK_NAME</code>).
 * @param pMessaggio messaggio da visualizzare
 */
public static void dispAlert(JFrame pFrame, String pTask, String pMessaggio) {
    //
    JOptionPane.showMessageDialog(pFrame, formattaHTML(pMessaggio), ALERT_TITLE, JOptionPane.OK_CANCEL_OPTION);
}

From source file:Main.java

private void fireTask(java.awt.event.ItemEvent evt) {
    if (evt.getStateChange() == 2) {
        int i = JOptionPane.showConfirmDialog(jComboBox1, "Message Text", "Title",
                JOptionPane.OK_CANCEL_OPTION);
        System.out.println("Result:" + i);
    }//from  ww w. j  a v a2  s. c om
}

From source file:Main.java

public Main() {
    options.add(createOptionPane("Plain Message", JOptionPane.PLAIN_MESSAGE));
    options.add(createOptionPane("Error Message", JOptionPane.ERROR_MESSAGE));
    options.add(createOptionPane("Information Message", JOptionPane.INFORMATION_MESSAGE));
    options.add(createOptionPane("Warning Message", JOptionPane.WARNING_MESSAGE));
    options.add(createOptionPane("Want to do something?", JOptionPane.QUESTION_MESSAGE));
    items = new Object[] { "First", "Second", "Third" };
    JComboBox choiceCombo = new JComboBox(items);
    options.add(new JOptionPane(choiceCombo, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION),
            "Question Message");
    JFrame frame = new JFrame("JOptionPane'Options");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(options, BorderLayout.CENTER);
    frame.pack();//  ww  w  .j  a v a  2 s  . c  om
    frame.setVisible(true);
}

From source file:Main.java

/**
 * visualizzazione messaggio HTML//from   w ww . ja  v  a 2s.  c o  m
 *
 * @param pFrame frame di provenienza (di solito e' <code>this</code>).
 * @param pTask task di provenienza del messaggio (di solito e'
 * <code>TASK_NAME</code>).
 * @param pMessaggio messaggio da visualizzare
 * @return JOptionPane.CANCEL_OPTION o OK_OPTION
 */
public static int dispWarning(JFrame pFrame, String pTask, String pMessaggio) {
    //
    return (JOptionPane.showConfirmDialog(pFrame, formattaHTML(pMessaggio), WARNING_TITLE,
            JOptionPane.OK_CANCEL_OPTION));
}

From source file:com.gs.obevo.util.inputreader.DialogInputReader.java

@Override
public String readLine(String promptMessage) {
    final JTextField juf = new JTextField();
    JOptionPane juop = new JOptionPane(juf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    JDialog userDialog = juop.createDialog(promptMessage);
    userDialog.addComponentListener(new ComponentAdapter() {
        @Override/*from www .  j  a va 2 s.  c o m*/
        public void componentShown(ComponentEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    juf.requestFocusInWindow();
                }
            });
        }
    });
    userDialog.setVisible(true);
    int uresult = (Integer) juop.getValue();
    userDialog.dispose();
    String userName = null;
    if (uresult == JOptionPane.OK_OPTION) {
        userName = new String(juf.getText());
    }

    if (StringUtils.isEmpty(userName)) {
        return null;
    } else {
        return userName;
    }
}

From source file:OptPaneComparison.java

public OptPaneComparison(final String message) {
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    final int msgType = JOptionPane.QUESTION_MESSAGE;
    final int optType = JOptionPane.OK_CANCEL_OPTION;
    final String title = message;

    setSize(350, 200);//  w  w w  .  j  a  v a 2 s.  c o m

    // Create a desktop for internal frames
    final JDesktopPane desk = new JDesktopPane();
    setContentPane(desk);

    // Add a simple menu bar
    JMenuBar mb = new JMenuBar();
    setJMenuBar(mb);

    JMenu menu = new JMenu("Dialog");
    JMenu imenu = new JMenu("Internal");
    mb.add(menu);
    mb.add(imenu);
    final JMenuItem construct = new JMenuItem("Constructor");
    final JMenuItem stat = new JMenuItem("Static Method");
    final JMenuItem iconstruct = new JMenuItem("Constructor");
    final JMenuItem istat = new JMenuItem("Static Method");
    menu.add(construct);
    menu.add(stat);
    imenu.add(iconstruct);
    imenu.add(istat);

    // Create our JOptionPane. We're asking for input, so we call
    // setWantsInput.
    // Note that we cannot specify this via constructor parameters.
    optPane = new JOptionPane(message, msgType, optType);
    optPane.setWantsInput(true);

    // Add a listener for each menu item that will display the appropriate
    // dialog/internal frame
    construct.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            // Create and display the dialog
            JDialog d = optPane.createDialog(desk, title);
            d.setVisible(true);

            respond(getOptionPaneValue());
        }
    });

    stat.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            String s = JOptionPane.showInputDialog(desk, message, title, msgType);
            respond(s);
        }
    });

    iconstruct.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            // Create and display the dialog
            JInternalFrame f = optPane.createInternalFrame(desk, title);
            f.setVisible(true);

            // Listen for the frame to close before getting the value from
            // it.
            f.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent ev) {
                    if ((ev.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY))
                            && (ev.getNewValue() == Boolean.TRUE)) {
                        respond(getOptionPaneValue());
                    }
                }
            });
        }
    });

    istat.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            String s = JOptionPane.showInternalInputDialog(desk, message, title, msgType);
            respond(s);
        }
    });
}

From source file:Main.java

@Override
public void actionPerformed(ActionEvent e) {
    MyPanel patientPicker = new MyPanel();
    int result = JOptionPane.showConfirmDialog(swingFoo, patientPicker, "Select Something",
            JOptionPane.OK_CANCEL_OPTION);
    if (result == JOptionPane.OK_OPTION) {
        swingFoo.setFileFieldText(patientPicker.getSelectedItem());
    }/*from   w  ww  .j  a v  a 2 s .  c  o m*/
    patientPicker.setVisible(true);
}

From source file:Main.java

/**
 * visualizzazione messaggio HTML da tabella errori.
 *
 * @param pFrame frame di provenienza (di solito e' <code>this</code>).
 * @param pTask task di provenienza del messaggio (di solito e'
 * <code>TASK_NAME</code>).//from   www.ja  va 2  s  .  c  o  m
 * @param pError codice del messaggio
 * @param pMessaggio ulteriori dati da visualizzare
 * @return JOptionPane.CANCEL_OPTION o OK_OPTION
 */
public static int dispWarning(JFrame pFrame, String pTask, String pError, String pMessaggio) {
    //
    return (JOptionPane.showConfirmDialog(pFrame, componiStringaWarning(pError, pMessaggio), WARNING_TITLE,
            JOptionPane.OK_CANCEL_OPTION));
}