Example usage for javax.swing JOptionPane setValue

List of usage examples for javax.swing JOptionPane setValue

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "The option pane's value object.")
public void setValue(Object newValue) 

Source Link

Document

Sets the value the user has chosen.

Usage

From source file:Main.java

/**
 * Set the option pane value./*from  w  w w .  j  a  va 2s. co  m*/
 *
 * @param c     The component.
 * @param value The value to set to the JOptionPane.
 */
public static void setOptionPaneValue(Component c, Object value) {
    JOptionPane optionPane = getOptionPane(c);
    if (optionPane != null) {
        optionPane.setValue(value);
    }
}

From source file:AddingButtonWithActionListener.java

public static JButton getButton(final JOptionPane optionPane, String text, Icon icon) {
    final JButton button = new JButton(text, icon);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            // Return current text label, instead of argument to method
            optionPane.setValue(button.getText());
            System.out.println(button.getText());
        }/*from   w w  w.j  a  v a2  s  .c  om*/
    };
    button.addActionListener(actionListener);
    return button;
}

From source file:MessagePopup.java

public static JButton getButton(final JOptionPane optionPane, String text, Icon icon) {
    final JButton button = new JButton(text, icon);
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            // Return current text label, instead of argument to method
            optionPane.setValue(button.getText());
        }//from   w  w w  . j a va 2s  .  co m
    };
    button.addActionListener(actionListener);
    return button;
}

From source file:gda.gui.mca.McaGUI.java

private void makeTcaControlDialog() {
    if (tcaControlPanel == null) {
        tcaControlPanel = new TcaPanel();
        tcaDialog = new JDialog();
        Object[] options = { "OK" };
        Object[] array = { tcaControlPanel };

        // Create the JOptionPane.
        final JOptionPane optionPane = new JOptionPane(array, JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_OPTION,
                null, options, options[0]);
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {

            @Override//  w w  w. ja v  a2s  . c  o m
            public void propertyChange(PropertyChangeEvent e) {
                String prop = e.getPropertyName();

                if (isVisible() && (e.getSource() == optionPane) && (JOptionPane.VALUE_PROPERTY.equals(prop)
                        || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
                    Object value = optionPane.getValue();

                    if (value == JOptionPane.UNINITIALIZED_VALUE) {
                        // ignore reset
                        return;
                    }

                    // Reset the JOptionPane's value.
                    // If you don't do this, then if the user
                    // presses the same button next time, no
                    // property change event will be fired.
                    optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

                    if ("OK".equals(value)) {

                        tcaDialog.setVisible(false);
                    }
                }

            }

        });
        tcaDialog.setContentPane(optionPane);
        tcaDialog.pack();
        tcaDialog.setTitle("TCA Controls");
        tcaDialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    }

}

From source file:gda.gui.mca.McaGUI.java

private void makeAdcControlDialog() {
    if (adcControlPanel == null) {
        adcControlPanel = new AdcPanel();
        adcDialog = new JDialog();
        Object[] options = { "OK" };
        Object[] array = { adcControlPanel };

        // Create the JOptionPane.
        final JOptionPane optionPane = new JOptionPane(array, JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_OPTION,
                null, options, options[0]);
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {

            @Override/*w  ww  .  j  av a2 s.c  om*/
            public void propertyChange(PropertyChangeEvent e) {
                String prop = e.getPropertyName();

                if (isVisible() && (e.getSource() == optionPane) && (JOptionPane.VALUE_PROPERTY.equals(prop)
                        || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
                    Object value = optionPane.getValue();

                    if (value == JOptionPane.UNINITIALIZED_VALUE) {
                        // ignore reset
                        return;
                    }

                    // Reset the JOptionPane's value.
                    // If you don't do this, then if the user
                    // presses the same button next time, no
                    // property change event will be fired.
                    optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

                    if ("OK".equals(value)) {

                        adcDialog.setVisible(false);
                    }
                }

            }

        });
        adcDialog.setContentPane(optionPane);
        adcDialog.pack();
        adcDialog.setTitle("ADC Controls");
        adcDialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    }

}