Set default option for option dialog created by JOptionPane in Java
Description
The following code shows how to set default option for option dialog created by JOptionPane.
Example
//from w w w. ja va 2 s. c o m
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
Object response = JOptionPane.showInputDialog(null,
"Where do you want to go tomorrow?",
"JOptionPane Sample", JOptionPane.QUESTION_MESSAGE,
null, new String[] { "A","B", "C","D","E" },"E");
System.out.println("Response: " + response);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »