Choice Option (Combo) In Java

In this section, you will learn how to create Drop-Down List by using Java AWT package.

Choice Option (Combo) In Java

In this section, you will learn how to create Drop-Down List by using Java AWT package.

Choice Option (Combo) In Java

Choice Option (Combo) In Java

     

In this section, you will learn how to create Drop-Down List by using Java AWT package.

Here, you will see in the output of the program that is given ahead for the illustration of the topic. This tells you about the procedure of constructing a drop down list in java by using java awt.

There is a program with complete java code that can be copied and paste in your java application for creating a combo box with some items, has been explained here:

Program Description:

Following program uses the Choice class for creating a Drop-Down List. This program is also using add() method of the Choice class for add item to the list like "ROSE", "INDIA" and "WELCOME".

Choice():- This is the default constructor of Choice class. This creates simply a drop-down list.

Here is the code of this program:

import java.awt.*;
import java.awt.event.*;
public class ChoiceOptionExample{
  public static void main(String[] args) {
  Frame frame=new Frame("Choice");
  Label label=new Label("What is your Choice:");
  Choice choice=new Choice();
  frame.add(label);
  frame.add(choice);
  choice.add("ROSE");
  choice.add("INDIA");
  choice.add("WELCOME");
  frame.setLayout(new FlowLayout());
  frame.setSize(250,150);
  frame.setVisible(true);
  frame.addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent e){
  System.exit(0);
   }
  });
  }
}

Output this program:

Download this Example: