Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Making a context menu look like a pop-up menu in BlackBerry 6

by Retired on ‎07-30-2010 03:50 PM - edited on ‎09-20-2010 05:05 PM by Retired (8,456 Views)

Summary

 

  • BlackBerry® Java® SDK 5.0, 6.0, and later
  • BlackBerry® JDE
  • BlackBerry Java Plug-in for Eclipse®
  • BlackBerry Java Plug-in for Microsoft® Visual Studio®

Description

 

With BlackBerry® 6, pop-up menus have replaced context menus (or short menus) to allow BlackBerry device users to perform the most common actions for a highlighted item quickly.

 

 2551i996D2B03BDB82FC1

 

The BlackBerry Java SDK 6.0 implementation of pop-up menus uses the new Command Framework API. This API supports defining common functionality once and using it from different parts of your application or from other applications on the BlackBerry device. If you’re not planning on upgrading your application to use the latest BlackBerry APIs, your application’s context menus are converted and displayed as pop-up menus.

 

Additionally, if your application was built using BlackBerry Java SDK 5.0, by adding an icon to a context menu item, you can easily make your converted context menu look as great as a pop-up menu built using BlackBerry Java SDK 6. In the following code sample, an icon is added to a context menu item. On devices running BlackBerry 6, this icon would be used in the pop-up menu.

 

import net.rim.device.api.system.Bitmap;

import net.rim.device.api.ui.*;

import net.rim.device.api.ui.component.*;

import net.rim.device.api.ui.container.*;

import net.rim.device.api.ui.image.*;

 

public class MyMenu extends UiApplication {

    public static void main(String[] args) {

        MyMenu theApp = new MyMenu();

        theApp.enterEventDispatcher();

    }

    public MyMenu() {

        pushScreen(new MyMenuScreen());

    }

}

class MyMenuScreen extends MainScreen {

    public MyMenuScreen() {

        setTitle("Conversion test");

    }

    private MenuItem item1 = new MenuItem("item1", 110, 10) {

        public void run() {

            Dialog.inform("item1");

        }

    };

    private MenuItem item2 = new MenuItem("item2", 110, 10) {

        public void run() {

            Dialog.inform("item2");

        }

    };

    public void makeMenu(Menu menu, int instance) {

        super.makeMenu(menu, instance);

 

        Bitmap bitmap = Bitmap.getBitmapResource("my_logo.png");

        Image image = ImageFactory.createImage(bitmap);

        item2.setIcon(image);

 

        if (instance == Menu.INSTANCE_DEFAULT) {

            menu.add(item1);

            item2.setIcon(null);

 

        }

        menu.add(item2);

    }

}

For more information on creating context menus, see http://supportforums.blackberry.com/t5/Java-Development/Distinguish-between-a-full-menu-and-a-primar....

Users Online
Currently online: 21 members 766 guests
Please welcome our newest community members: