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.
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-Develo