JOptionPane with drop down list java code example

Example: JOptionPane with drop down list java

package com.mkyong.inputDialog;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class InputDialog6a {

    public static void main(String[] args) {

        String[] options = {"I adore turtles", "Yes", "Maybe", "Urm...", "No", "Hate them"};
        ImageIcon icon = new ImageIcon("src/images/turtle32.png");
        String n = (String)JOptionPane.showInputDialog(null, "Do you like turtles??", 
                "I like turtles", JOptionPane.QUESTION_MESSAGE, icon, options, options[2]);
        System.out.println(n);

    }

}
Copy

Tags:

Misc Example