Example usage for javax.swing JOptionPane showInputDialog

List of usage examples for javax.swing JOptionPane showInputDialog

Introduction

In this page you can find the example usage for javax.swing JOptionPane showInputDialog.

Prototype

@SuppressWarnings("deprecation")
public static Object showInputDialog(Component parentComponent, Object message, String title, int messageType,
        Icon icon, Object[] selectionValues, Object initialSelectionValue) throws HeadlessException 

Source Link

Document

Prompts the user for input in a blocking dialog where the initial selection, possible selections, and all other options can be specified.

Usage

From source file:ManyOptions.java

public static void main(String[] args) {
    JOptionPane.showInputDialog(null, "Please choose a name", "Example 1", JOptionPane.QUESTION_MESSAGE, null,
            new Object[] { "Amanda", "Colin", "Don", "Fred", "Gordon", "Janet", "Jay", "Joe", "Judie",
                    "Kerstin", "Lotus", "Maciek", "Mark", "Mike", "Mulhern", "Oliver", "Peter", "Quaxo", "Rita",
                    "Sandro", "Tim", "Will" },
            "Joe");
}

From source file:InputDialog.java

public static void main(String argv[]) {
    String input = (String) JOptionPane.showInputDialog(new JFrame(),
            "Please enter your favorite Shakespeare play", "Title", JOptionPane.INFORMATION_MESSAGE,
            new ImageIcon("java2sLogo.GIF"), null, "Romeo and Juliet");
    System.out.println("User's input: " + input);
}

From source file:InputDialogWithDropdownListbox.java

public static void main(String[] a) {
    String[] choices = { "A", "B", "C", "D", "E", "F" };
    String input = (String) JOptionPane.showInputDialog(null, "Choose now...", "The Choice of a Lifetime",
            JOptionPane.QUESTION_MESSAGE, null, // Use
            // default
            // icon
            choices, // Array of choices
            choices[1]); // Initial choice
    System.out.println(input);//from w w  w . java 2  s. c o  m
}

From source file:Main.java

public static void main(String[] args) {
    String[] possibilities = { "Adult Ticket", "Childs Ticket", "Over Fifty Ticket" };
    String s = (String) JOptionPane.showInputDialog(null, "What ticket would you like to buy?", "Ticket Dialog",
            JOptionPane.PLAIN_MESSAGE, null, possibilities, possibilities[0]);
    switch (s) {//from   w  ww  .  j  a  va2s  . c  o  m
    case "Adult Ticket":
        System.out.println("Buy Adult");
        break;
    case "Childs Ticket":
        System.out.println("Child Adult");
        break;
    case "Over Fifty Ticket":
        System.out.println("Over Fifty Adult");
        break;
    }
}

From source file:ComboBoxDialog.java

public static void main(String argv[]) {
    String[] plays = new String[] { "Hamlet", "King Lear", "Otello", "Romeo and Juliet" };
    String input = (String) JOptionPane.showInputDialog(new JFrame(),
            "Please select your favorite Shakespeare play", "Title", JOptionPane.INFORMATION_MESSAGE,
            new ImageIcon("java2sLogo.GIF"), plays, "Romeo and Juliet");
    System.out.println("User's input: " + input);
}

From source file:JOptionPaneTest3.java

public static void main(String[] args) {
    JDialog.setDefaultLookAndFeelDecorated(true);
    Object[] selectionValues = { "Pandas", "Dogs", "Horses" };
    String initialSelection = "Dogs";
    Object selection = JOptionPane.showInputDialog(null, "What are your favorite animals?", "Zoo Quiz",
            JOptionPane.QUESTION_MESSAGE, null, selectionValues, initialSelection);
    System.out.println(selection);
}

From source file:BigValueJOptionpaneDialog.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    String bigList[] = new String[30];

    for (int i = 0; i < bigList.length; i++) {
        bigList[i] = Integer.toString(i);
    }/*from w w  w  .  j  a v  a  2s . com*/

    JOptionPane.showInputDialog(frame, "Pick a printer", "Input", JOptionPane.QUESTION_MESSAGE, null, bigList,
            "Titan");

}

From source file:Main.java

public static void main(String[] args) {
    Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon");
    Object[] possibilities = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
    Integer i = (Integer) JOptionPane.showOptionDialog(null, null, "ShowInputDialog", JOptionPane.PLAIN_MESSAGE,
            1, errorIcon, possibilities, 0);
    Integer ii = (Integer) JOptionPane.showInputDialog(null, "Select number:\n\from JComboBox",
            "ShowInputDialog", JOptionPane.PLAIN_MESSAGE, errorIcon, possibilities, "Numbers");
}

From source file:Main.java

public static void main(String[] args) {
    Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon");
    Object[] possibilities = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    Integer i = (Integer) JOptionPane.showOptionDialog(null, null, "ShowInputDialog", JOptionPane.PLAIN_MESSAGE,
            1, errorIcon, possibilities, 0);

    // or//  www . j  av a2s . c o m

    Integer ii = (Integer) JOptionPane.showInputDialog(null, "Select number:\n\from JComboBox",
            "ShowInputDialog", JOptionPane.PLAIN_MESSAGE, errorIcon, possibilities, "Numbers");

}

From source file:Main.java

public static void main(String[] args) {
    Object[] options = { "Option 1", "Option 2", "Option 3", "None of the above" };
    JComboBox optionControl = new JComboBox(options);
    optionControl.setSelectedIndex(3);//w w  w  .  j  a  v a 2 s.co  m
    JOptionPane.showMessageDialog(null, optionControl, "Option", JOptionPane.QUESTION_MESSAGE);
    System.out.println(optionControl.getSelectedItem());

    String graphSelection = (String) JOptionPane.showInputDialog(null, "Choose from the following options...",
            "Choose From DropDown", JOptionPane.QUESTION_MESSAGE, null, options, options[3]);
    System.out.println(graphSelection);

    JOptionPane.showMessageDialog(null, optionControl, "Option", JOptionPane.QUESTION_MESSAGE);
}