Java Reference
In-Depth Information
With the exception of CustomItem subclasses—which I discuss in detail in the last
section of this chapter— Item subclasses take care of their own drawing. You can, however,
customize the drawing behavior of some items. For example, most items accept a label,
which is a string that precedes the item and is drawn in a read-only fashion. The Item
class provides the methods getLabel and setLabel to get and set the label, and it provides
constants to suggest button or hyperlink style via the constructor of specific Item sub-
classes such as StringItem .
Finally, Item instances signal their preferences as to how they should be laid out in
the parent Form to the parent Form . They do this through the layout constant you set via
the setLayout method. The Form class provides layout flags for indicating that an item
should be aligned to the top, bottom, left, right, or center of its viewable rectangle, that
an item should be shrunk to its minimum bounds or expanded as much as possible,
and whether an item should appear on a subsequent line or whether other items
should appear on their own line after it. These layout flags all affect the row-based
layout policy of the Form , which you'll encounter in the section “Collecting Visible
Items Using the Form Class” later in this chapter. You can also query an Item for its
minimum or preferred size using one or more of these four methods: getMinimumHeight ,
getMinimumWidth , getPreferredHeight , and getPreferredWidth . You use these in conjunc-
tion with setPreferredSize , which indicates the size of the viewable item in which you'd
like the Form to present the item.
When using NetBeans, if you're editing a Form in the Screen Design view, you can
select any of the supported items by choosing one from the Form Items section of the
Palette (whose location defaults to the upper right-hand portion of the display). In fact, if
you're using NetBeans, odds are that you won't instantiate any of these classes from your
source code directly, but will instead rely on the code-generation facility to write that
code for you.
Tip The properties of Items (and Displayables ) that you can change are all also available in the
Properties window of NetBeans. In general, if you're using NetBeans to build your user interface, you'll need
to understand the properties available to a particular Item, but you won't necessarily need to know the inter-
face to mutate those properties, because you set the property on the Item in NetBeans, and NetBeans'
automatic code-generation facility does the rest.
Introducing the Spacer
Because you can't specify pixel positions for user-interface items, the MIDP imple-
mentation provides the Spacer class. Instances of the Spacer class take a minimum
size on creation and can be used to place pads between adjacent (horizontally or
vertically) items.
 
Search WWH ::




Custom Search