Create option dialog with JOptionPane for more than two option values in Java

Description

The following code shows how to create option dialog with JOptionPane for more than two option values.

Example


/*from w w w .j av a  2 s .c  o m*/
import javax.swing.JOptionPane;

public class Main {
  public static void main(String[] args) {
        Object[] selections = { "First", "Second", "Third" };
        Object val = JOptionPane.showInputDialog(null, "Choose one",
            "Input", JOptionPane.INFORMATION_MESSAGE, null,
            selections, selections[0]);
        if (val != null)
          System.out.println(val.toString());
  }
}

The code above generates the following result.

Create option dialog with JOptionPane for more than two option values in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer