Java Reference
In-Depth Information
The
Form
class's layout policy centers around rows, by default positioning each
Item
next to the previous as long as multiple
Item
s fit on a single line. If there are more
Item
s
than fit on a single line,
Item
s are placed on rows one below the other. In the unlikely
event that there are more
Item
s than fit on the display, the MIDP implementation may
choose to provide a scrolling view of the
Item
s on the
Form
, or may paginate the
Form
,
taking you to a new screen to view additional
Item
s on the
Form
.
The layout algorithm provides default layout constraints for each
Item
added to a
Form
. For example, if the
Form
is laying out
Item
s left to right, an
Item
with an unspecified
layout policy will default to
LAYOUT_LEFT
, left-aligned on the
Form
. If the
Item
specifies
another layout policy, such as
LAYOUT_CENTER
, then the
Form
will attempt to accommodate
the desired layout for the
Item
on the
Form
. As the
Item
s are laid out on the
Form
, the layout
algorithm attempts to keep subsequent
Item
s next to each other, unless any of the follow-
ing occurs:
• The previous
Item
has a row break after it.
• The current
Item
has the
LAYOUT_NEWLINE_BEFORE
layout hint set.
• The current
Item
is a
StringItem
that begins with
\n
.
• The current
Item
is a
ChoiceGroup
,
DateField
,
Gauge
, or
TextField
, and the
LAYOUT_2
hint is not set.
• The current
Item
has a layout flag that differs from the form's current alignment.
A row break occurs after an
Item
if any of the following occurs:
• The
Item
is a
StringItem
that ends with
\n
.
• The
Item
has the
LAYOUT_NEWLINE_AFTER
hint set.
• The
Item
is a
ChoiceGroup
,
DateField
,
Gauge
, or
TextField
, and the
LAYOUT_2
hint is
not set.
If all of this seems confusing, don't panic: the behavior is actually fairly intuitive, and
you'll find in practice that a bit of experimentation quickly yields the layout you want.
The
Form
's other responsibility is to keep a collection of the
Item
s it draws. While the
details of that collection are private to the implementation of the
Form
class, the
Form
class
provides the following methods:
•
append
: Appends an
Item
to the
Form
•
delete
: Takes an index and deletes the
Item
at the specified index in its collection
from the
Form