Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
AWT List
Class declaration
AWT List Constructors
AWT List Methods
Java AWT List Example
Example 1
Example 2
Frequently Asked Questions
What is AWT?
How many items can be selected from the list at a time?
Which library package needs to import to use awt List?
Last Updated: Mar 27, 2024

AWT List

0 upvote
Master Power BI using Netflix Data
Ashwin Goyal
Product @
18 Jun, 2024 @ 01:30 PM


The List is a GUI component that displays a list of String values from which the user can select one or more values. The list can be configured as per the choice, and it can be configured as ‘single select’ or ‘multiple select.’ It inherits a component class.

Also Read About, Multithreading in java

AWT List

The AWT list is a component in AWT that extends the Component class. It is used to create a list with multiple values, and from those lists, a user can select any of the values. When the values are selected, then an ItemEvent gets generated, which is handled by implementing the ItemListener interface. Selecting and deselecting items from the list can be done at runtime if any class is implementing this interface. We will see these things through a simple example in a later section.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

Class declaration

Following is the declaration for java. awt.List class:

public class List extends Component implements ItemSelectable, Accessible


Now, let’s see AWT List Class Constructors.

AWT List Constructors

AWT List Methods

To perform the operations on the list, we have so many methods. Some of the important and most used methods are:

You can also read about the Multiple Inheritance in Java.

Java AWT List Example

Example 1

We will create a list of components with 5 rows and add them to the frame in this example.

// importing awt class  
import java.awt.*;

public class ListExample1 {
   // class constructor
   ListExample1() {
      // creating the frame
      Frame f = new Frame();
      // creating the list of 5 rows
      List l1 = new List(5);

      // setting the position of list component
      l1.setBounds(100, 100, 75, 75);

      // adding list items into the list
      l1.add("Item 1");
      l1.add("Item 2");
      l1.add("Item 3");
      l1.add("Item 4");
      l1.add("Item 5");

      // adding the list to frame

      // setting size, layout and visibility of frame
      f.setSize(400, 400);

   // main method
   public static void main(String args[]) {
      new ListExample1();



Try and compile it on java online compiler.

In this example, we have created a frame, and then we have created a list of size 5. We have 5 dummy data, and after adding these data, we set the size, layout, and visibility of the frame.

Example 2

import java.awt.*;

public class CreateList {
    CreateList() {
        Frame frame = new Frame();
        List list1 = new List(5, true);
        List list2 = new List(2);




        list1.setBounds(50, 50, 100, 60);
        list2.setBounds(50, 200, 100, 60);

        frame.setSize(300, 300);


    public static void main(String[] args) {
        CreateList obj = new CreateList();


We have created two lists objects, List1, and List2. List1 has an initial size of 5 rows, but we have added only 3 items to it. Similarly, List2 has an initial size of 2 rows, but we have added 5 items. 

In the object constructor, the first parameter specifies the row size, and the second parameter is a boolean value that specifies whether the user can select single or multiple values. If the second parameter is false, then the user can select only one item from the list, as in the case of list 2. If the parameter is true, then the user can select multiple items from the list, as in the case of list 1.

Know about Single Inheritance in Java in detail.

Frequently Asked Questions

What is AWT?

It stands for Abstract Window Toolkit. It is an API that Java programmers use to create GUI(Graphical User Interface) objects such as scroll bars, windows, and buttons.

How many items can be selected from the list at a time?

If the list is configured as ‘single select,’ you can select only one item from the list, and if it is configured as ‘multiple select,’ you can select multiple items from the list.

Which library package needs to import to use awt List?

We need to import class java. awt.List.


In this article, we have discussed the AWT List through different examples. We also discussed the constructors and methods of the AWT List.

Enhance your skills in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and more with our Coding Ninjas Studio  Guided Path. If you want to sharpen your coding skills to the test, check out the mock test series and enter the contests on Coding Ninjas Studio! If you are just a beginner and want to know what questions big giants like Amazon, Microsoft, and Uber ask, check the problemsinterview experiences, and interview bundle for placement preparations.

You may consider our paid courses curated by experts to give your career an edge over others!

Do Upvote and Happy Learning!