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.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »