In addition to the generic commands, there are specialised commands that are used for certain types of action: default command, select command, back command, and clear command.
Figure: Commands on touch and type UI
Figure: Commands on full touch UI
setDefaultCommand(Command cmd)
This method adds the Command into the middle of the MenuBar in Series 40 touch and type and non-touch phones, and on top right corner of the screen in Series 40 full touch phones. The default command can be described as a command that does a specific action for the whole Form.
DefaultCommand is not shown if there is a SelectCommand set. This is often the case in non-touch phones, where you need SelectCommand to interact with most Form items. In this case the DefaultCommand will appear in the Options menu. When the SelectCommand is removed, the DefaultCommand will return to the middle position of the MenuBar.
MenuBar.setSelectCommand(Command cmd)
This also adds the command into the middle of the MenuBar. It should be used in Series 40 non-touch phones when you have a specific action that is related to the currently focused component — for example, a TextField that displays "Edit" command when it is focused. Note that this method is only available via the MenuBar class. If you have SelectCommand defined, it will override the DefaultCommand in the MenuBar.
setBackCommand(command cmd)
This sets the Command in the rightmost slot of the MenuBar in Series 40 touch and type and non-touch phones, and in the platform's Back button in the bottom right corner of the screen in Series 40 full touch phones.
If the ClearCommand is defined, it will override the BackCommand. In this case the BackCommand will not appear in menu, and will return to the menu when the ClearCommand is removed. Note that the name BackCommand just means that this command will appear in a place where you usually would set a back action. LWUIT does not have any automatic functionality for navigating back in the views; the developer is responsible for implementing the back navigation.
BackCommand is never displayed in the Menu.
setClearCommand(Command cmd)
This also sets the Command to the right of the MenuBar. If there is a BackCommand assigned, the ClearCommand will override it. The BackCommand will appear when ClearCommand is removed. A Command that is set as ClearCommand should do something that is related to deleting or clearing out something in a component.
ClearCommand is not applicable in Series 40 full touch phones, because in them the clear functionality is provided by the virtual keyboard.
The Series 40 full touch phones introduce a new IconCommand API. This API has been integrated to LWUIT so that when you add an icon to your LWUIT Command, it will be automatically converted to IconCommand, and the icon will be shown either in the Action button 1 in the upper right corner, or in the Category bar.
If you do not define any icon to your default command, the default tick mark is used in the Action button 1.
Though it is technically possible to show icons on LWUIT commands on touch and type and non-touch phones, it is not according to Series 40 UI style. Thus you can use the Display.getInstance().getDeviceType() to get the current device type and set an icon only on full touch devices.
Below is a code snippet on icon command use (taken from RLinks example application that is available in available in the <Nokia SDK 2.0 for Java installation directory>\plugins\lwuit\examples directory):
if (Display.getInstance().getDeviceType() == Display.FULL_TOUCH_DEVICE) { Image icon = Main.getResources().getImage("refresh.png"); refreshCommand = new Command("Refresh", icon); } else { refreshCommand = new Command("Refresh"); }