:: Reference :: Bounded Sizes ::
Bounded sizes are used to restrict a layout element's initial size.
They add context related layout information that the element
does not or cannot provide.
To use a bounded size, you typically combine a component size
(min, pref or default) with a constant size as lower or upper bound.
For example, a well designed command button honors the
button's label and icon size, but also uses a minimum width.
The latter increases the design consistency and often
makes it easier to click on buttons with short labels.
A Swing JButton is used in different contexts:
form, button bar, button stack, toolbar with icons, toolbar with texts,
toolbar in large button mode, etc. Since the JButton (or the
ButtonUI) can only provide a single preferredSize
that often lacks the context. And so, the button lacks information
about context-related layout requirements.
String Representations
String representations for bounded sizes are used in
the FormLayout constructors as well as in classes
ColumnSpec, RowSpec and Border.
The string encodings allow to set only a lower or
upper bound, where the related Java objects allow to set both
bounds at the same time, which is needed rarely.
boundedSize ::= [constantSize,componentSize] // lower bound
| [componentSize,constantSize] // upper bound
| [constantSize,componentSize,constantSize] // lower and upper
| MAX(constantSize;componentSize) // lower bound (old)
| MIN(constantSize;componentSize) // upper bound (old)
Examples
ColumnSpec.decode("[50dlu,pref]"); // pref size with lower bound 50dlu
RowSpec.decode("[pref,80dlu]"); // pref size with upper bound 80dlu
new FormLayout("[50dlu,pref], 4dlu, [100dlu,min]",
"p, 3dlu, p, 3dlu, [200dlu,p]:grow");
|