All Packages Class Hierarchy This Package Previous Next Index
Class com.sun.java.swing.SizeRequirements
java.lang.Object
|
+----com.sun.java.swing.SizeRequirements
- public class SizeRequirements
- extends Object
- implements Serializable
For the convenience of layout managers,
calculates information about the size and position of components.
All size and position calculation methods are class methods
that take arrays of SizeRequirements as arguments.
The SizeRequirements class supports two types of layout:
- tiled
- The components are placed end-to-end,
starting at coordinate 0
(the leftmost or topmost position).
- aligned
- The components are aligned as specified
by each component's X or Y alignment value.
Each SizeRequirements object contains information
about either the width (and X alignment)
or height (and Y alignment)
of a single component or a group of components:
-
minimum
- The smallest reasonable width/height of the component
or component group, in pixels.
-
preferred
- The natural width/height of the component
or component group, in pixels.
-
maximum
- The largest reasonable width/height of the component
or component group, in pixels.
-
alignment
- The X/Y alignment of the component
or component group.
- See Also:
- getMinimumSize, getPreferredSize, getMaximumSize, getAlignmentX, getAlignmentY
-
alignment
-
The alignment, specified as a value between 0.0 and 1.0,
inclusive.
-
maximum
-
The maximum size allowed.
-
minimum
-
The minimum size required.
-
preferred
-
The preferred (natural) size.
-
SizeRequirements()
- Creates a SizeRequirements object with the minimum, preferred,
and maximum sizes set to zero and an alignment value of 0.5
(centered).
-
SizeRequirements(int, int, int, float)
- Creates a SizeRequirements object with the specified minimum, preferred,
and maximum sizes and the specified alignment.
-
calculateAlignedPositions(int, SizeRequirements, SizeRequirements[], int[], int[])
- Creates a bunch of offset/span pairs specifying how to
lay out a set of components with the specified alignments.
-
calculateTiledPositions(int, SizeRequirements, SizeRequirements[], int[], int[])
- Creates a bunch of offset/span pairs representing how to
lay out a set of components end-to-end.
-
getAlignedSizeRequirements(SizeRequirements[])
- Determines the total space necessary to
align a set of components.
-
getTiledSizeRequirements(SizeRequirements[])
- Determines the total space necessary to
place a set of components end-to-end.
-
toString()
- Returns a string describing the minimum, preferred, and maximum
size requirements, along with the alignment.
minimum
public int minimum
- The minimum size required.
For a component
comp
, this should be equal to either
comp.getMinimumSize().width
or
comp.getMinimumSize().height
.
preferred
public int preferred
- The preferred (natural) size.
For a component
comp
, this should be equal to either
comp.getPreferredSize().width
or
comp.getPreferredSize().height
.
maximum
public int maximum
- The maximum size allowed.
For a component
comp
, this should be equal to either
comp.getMaximumSize().width
or
comp.getMaximumSize().height
.
alignment
public float alignment
- The alignment, specified as a value between 0.0 and 1.0,
inclusive.
To specify centering, the alignment should be 0.5.
SizeRequirements
public SizeRequirements()
- Creates a SizeRequirements object with the minimum, preferred,
and maximum sizes set to zero and an alignment value of 0.5
(centered).
SizeRequirements
public SizeRequirements(int min,
int pref,
int max,
float a)
- Creates a SizeRequirements object with the specified minimum, preferred,
and maximum sizes and the specified alignment.
toString
public String toString()
- Returns a string describing the minimum, preferred, and maximum
size requirements, along with the alignment.
- Overrides:
- toString in class Object
getTiledSizeRequirements
public static SizeRequirements getTiledSizeRequirements(SizeRequirements children[])
- Determines the total space necessary to
place a set of components end-to-end. The needs
of each component in the set are represented by an entry in the
passed-in SizeRequirements array.
The returned SizeRequirements object has an alignment of 0.5
(centered).
- Parameters:
- children - the space requirements for a set of components.
- Returns:
- the total space requirements.
getAlignedSizeRequirements
public static SizeRequirements getAlignedSizeRequirements(SizeRequirements children[])
- Determines the total space necessary to
align a set of components. The needs
of each component in the set are represented by an entry in the
passed-in SizeRequirements array.
- Parameters:
- children - the set of child requirements.
- Returns:
- the total space requirements.
calculateTiledPositions
public static void calculateTiledPositions(int allocated,
SizeRequirements total,
SizeRequirements children[],
int offsets[],
int spans[])
- Creates a bunch of offset/span pairs representing how to
lay out a set of components end-to-end.
This method requires that you specify
the total amount of space to be allocated,
the size requirements for each component to be placed
(specified as an array of SizeRequirements), and
the total size requirement of the set of components.
You can get the total size requirement
by invoking the getTiledSizeRequirements method.
- Parameters:
- allocated - the total span to be allocated.
- total - the total of the children requests.
- children - the size requirements for each component.
- offset - the offset from 0 for each child where
the spans were allocated (determines placement of the span).
- spans - the span allocated for each child to make the
total target span.
calculateAlignedPositions
public static void calculateAlignedPositions(int allocated,
SizeRequirements total,
SizeRequirements children[],
int offsets[],
int spans[])
- Creates a bunch of offset/span pairs specifying how to
lay out a set of components with the specified alignments.
The resulting span allocations will overlap, with each one
fitting as well as possible into the given total allocation.
This method requires that you specify
the total amount of space to be allocated,
the size requirements for each component to be placed
(specified as an array of SizeRequirements), and
the total size requirements of the set of components
(only the alignment field of which is actually used).
You can get the total size requirement by invoking
getAlignedSizeRequirements.
- Parameters:
- allocated - the total span to be allocated.
- total - the total of the children requests.
- children - the size requirements for each component.
- offset - the offset from 0 for each child where
the spans were allocated (determines placement of the span).
- spans - the span allocated for each child to make the
total target span.
All Packages Class Hierarchy This Package Previous Next Index