Thursday, 5 February 2015

How to add option list in option pane

There are many situations where we  need to add list of options in option pane .This tutorial shows how to add option list in option pane in a simple way.

CODING:

import javax.swing.*;

public class copy {
  public static void main(String[] args) {
    Object[] option = { "Java", "C#", "C++" };
    String initialoption = "Java";
    Object selected = JOptionPane.showInputDialog(null, "What are your favorite animals?",
        "Output Sample", JOptionPane.QUESTION_MESSAGE, null, option, initialoption);
    System.out.println(selected);
  }
}

OUTPUT:




No comments:

Post a Comment