by Dinesh Thakur Category: AWT and Applets

A popupmenu is a small window that pops up and displays a list of choices such as Cut, Copy, Paste, Select All etc. This menu is invisible until the user makes a platform specific mouse action such as pressing the right mouse button over a popup enabled component. The popup menu then appears under the cursor.

In order to create a pop up menu, java .awt .PopupMenu class is used. It is a subclass of Menu and is used very much like a Menu. It provides the following two constructors

• PopupMenu () - Creates an empty popup menu.

• PopupMenu (String title) - Creates an empty pop up menu with the as the title of the popup menu.

As expected, the AWT provides fairly complete support for creating applications using the menu bar (menu bar), drop down menus (pull-down menus) and  independent menu (pop-up menus) through set of classes briefly described following:




Abstract class that defines the behavior and structure Basic elements of the components menu.


class that defines a simple menu entry.


class that defines a menu bar for an application.


Class that defines a menu dropdown.


class that defines a shortcut to a menu item.


class that defines a menu entry type option.


class that defines an independent menu.

import java.awt.*;

class PopupMenuExample extends Frame
     PopupMenu popupMenu;
     public PopupMenuExample()
           setLayout(new FlowLayout());
           popupMenu = new PopupMenu();
           popupMenu.add(new MenuItem("Cut"));
           popupMenu.add(new MenuItem("Cut"));
           popupMenu.add(new MenuItem("paste"));
           setTitle("PopupMenu in Java Example");
 class PopupMenuJavaExample
        public static void main(String[] args)
            PopupMenuExample frame = new PopupMenuExample();

PopupMenu in Java Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles