Java Reference
In-Depth Information
the implementation, “I don't care, you go ahead and figure out the best size for this item.”
If you pass a specific positive value for the width or height in setPreferredSize() , that dimension
is said to be locked and the implementation will attempt to use it during layout.
The getPreferredWidth() and getPreferredHeight() methods don't always return the
values you've passed to setPreferredSize() . For example, if you've unlocked the width and
height by calling setPreferredSize(-1, -1) , the values returned from getPreferredWidth()
and getPreferredHeight() are the preferred sizes that the implementation has computed.
Finally, the Item class includes a layout directive, accessed using getLayout() and setLayout() .
Represented by an integer, the layout value is usually a combination of LAYOUT_2 with a horizontal
value and a vertical value. LAYOUT_2 is a flag to the implementation that the item should be laid
out using MIDP 2 rules. The previous MIDP version (1.0) had very limited layout control
capabilities. The horizontal values are
LAYOUT_LEFT
LAYOUT_RIGHT
LAYOUT_CENTER
The vertical values are
LAYOUT_TOP
LAYOUT_BOTTOM
LAYOUT_VCENTER
In addition, a layout value may include shrinking or expanding . Shrinking means that an
item's minimum width or height is used, while expanding means that an item's size is stretched
to fill the available width or row height. The constants for shrinking and expanding are
LAYOUT_SHRINK (for width)
LAYOUT_EXPAND (for width)
LAYOUT_VSHRINK (for height)
LAYOUT_VEXPAND (for height)
Finally, an Item 's layout may include a request for a new line before or after the item using
the LAYOUT_NEWLINE_BEFORE or LAYOUT_NEWLINE_AFTER constants. Item s are laid out in Form s much
like text flows on a page, so these constants allow you to request a new row before or after an item.
Figure 6-5 shows a simple example, three components with the following layouts:
LAYOUT_2 | LAYOUT_LEFT | LAYOUT_NEWLINE_AFTER
LAYOUT_2 | LAYOUT_CENTER | LAYOUT_NEWLINE_AFTER
• LAYOUT_2 | LAYOUT_RIGHT | LAYOUT_NEWLINE_AFTER
Search WWH ::




Custom Search