Java examples for Swing:JOptionPane
The user may select one of the choices from the list.
import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { JComponent parentComponent = null; Object message = "Please select your opinion about JOptionPane"; String title = "JOptionPane Input Dialog"; int messageType = JOptionPane.INFORMATION_MESSAGE; Icon icon = null;/*from w ww . j ava 2 s . c om*/ Object[] selectionValues = new String[] { "A", "B", "C" }; Object initialSelectionValue = selectionValues[2]; Object response = JOptionPane.showInputDialog(parentComponent, message, title, messageType, icon, selectionValues, initialSelectionValue); if (response == null) { System.out.println("You have cancelled the input dialog."); } else { System.out.println("You entered: " + response); } } }