Java Reference
In-Depth Information
Note how the toolkit emulator indicates the presence of one or more commands on the
item with a light underline. When you navigate through the form to the item with the additional
command, it shows up just like any other command, as shown in Figure 6-4.
Figure 6-4. When an item is selected, its commands are shown.
The semantics for managing item commands are nearly identical to the semantics for
managing form commands. You can manage the commands on an Item using addCommand()
and removeCommand() . Note that the command type should be ITEM for commands added to
Item , although no exception will be thrown if this is not true. A command listener may be
assigned using the setItemCommandListener() method. The ItemCommandListener interface
contains a single method, similar to CommandListener 's single method:
public void commandAction(Command c, Item item)
It's up to the implementation to figure out how to show commands for an item. All you do
in a MIDlet is add commands, set a listener, and wait for command events.
Item s also support a default command . This command may be invoked if the runtime
device has a button or knob or other user interface control that is appropriate for a default
command. You can set an Item 's default command by calling setDefaultCommand() .
Item has fields that are related to layout control. Item s have a minimum size and a preferred
size that can be used to control how large an item appears in a form. The minimum size is
computed by the implementation and can be retrieved using getMinimumWidth() and
getMinimumHeight() . The minimum size depends on the contents of the Item and can be
changed by the implementation every time the contents change. There's no way to change an
item's minimum size, but examining the minimum size may be useful to your application in
deciding how to lay out a form.
The preferred size, by contrast, can either be computed by the implementation or speci-
fied by you. The default values for preferred width and height are -1 , a special value that tells
 
Search WWH ::




Custom Search