Create a option dialog with JOptionPane in Java
Description
The following code shows how to create a option dialog with JOptionPane.
Example
import javax.swing.JOptionPane;
/*from w ww . j av a 2s . c om*/
public class Main {
public static void main(String[] args) {
Object[] options = { "Red", "Green" };
int sel = JOptionPane.showOptionDialog(null, "Choose a Color!",
"Warning", JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE, null, options, options[0]);
if (sel != JOptionPane.CLOSED_OPTION)
System.out.println("Color Selected: " + options[sel]);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »