Featured classes


This class provides a menu that is displayed when users press the Menu key. It consists of methods for populating the menu with objects (MenuItem objects, for example), and for customizing the appearance of the menu, (setFont(Font font), for example).

In the sample application, the menu is populated with MenuItem, SubMenu, and SeparatorField objects. Selecting the different options dynamically changes which objects are added to the menu, as well as how it looks.


This class creates submenus that are added to menus. The submenu is populated by MenuItem objects, that are added to the Menu object by invoking Menu.add(Submenu submenu).

In the sample application, the submenu is added to the menu object when you select the "Menu with sub menu" option. The submenu in the sample application is populated with DemoMenuItem objects, a subclass of MenuItem created in the sample application.


This class creates an object that represents an abstract menu item.

The sample application uses two subclasses of the MenuItem class, DemoMenuItem and ImageMenuItem. DemoMenuItem is created as an inner class, and demonstrates the SubMenu class by populating a SubMenu with DemoMenuItem objects. ImageMenuItem demonstrates how to add an image to menu items.

Files in the sample application


This file defines four classes, MenuDemo, MenuDemoScreen, DemoMenuItem, and ImageMenuItem.

The MenuDemo class extends UiApplication to support a user interface and contains the following constructor and methods:

  • main (String[] args): provides the entry point to the sample application and starts the main thread using enterEventDispatcher() from UiApplication
  • MenuDemo(): constructs a new MenuDemo object, then creates an MenuDemoScreen object and displays it

The MenuDemoScreen class extends MainScreen to create the screen of the application, and implements the FieldChangeListener interface to listen for changes in the state of the fields on the screen. The MenuDemoScreen class contains the following constructor, methods and classes:

  • MenuDemoScreen(): constructs a new MenuDemoScreen object, containing several types of fields, and adds these fields to the screen manager inherited from MainScreen, as well as three DemoMenuItem objects to populate the SubMenu
  • fieldChanged(Field field, int context): implements fieldChanged(Field field, int context) of the FieldChangeListener interface. When a BlackBerry® device user selects the appropriate RadioButtonField object, the ObjectChoiceField object becomes editable
  • makeMenu(Menu menu, int context): overrides MainScreen.MakeMenu(Menu menu, int context) to modify the default menu by adding menu items, sub menus, and images to menu items based on the fields that you select
  • DemoMenuItem: an inner class with no executable code that extends MenuItem to demonstrate the Sub Menu API
  • onSavePrompt(): a method from the MainScreen class overridden to return true, suppressing the save dialog before closing

The ImageMenuItem class extends MenuItem, and contains the following constructor:

  • ImageMenuItem(): class constructor, which creates a menu item with an icon using the inherited MenuItem.setIcon(Image arg0) method

Resource files




Image that is used as an icon in the ImageMenuItem class.

Next topic: System requirements
Previous topic: Overview

Was this information helpful? Send us your comments.