APIdia Launch Partner
Top Description Fields Constructors Methods
javax.swing

public Class SizeRequirements

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Annotations
@SuppressWarnings:serial
Imports
java.awt.*, java.io.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 either at coordinate 0 (the leftmost or topmost position) or at the coordinate representing the end of the allocated span (the rightmost or bottommost 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.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Author
Timothy Prinzing
Since
1.2
See Also
Component#getMinimumSize, Component#getPreferredSize, Component#getMaximumSize, Component#getAlignmentX, Component#getAlignmentY

Field Summary

Modifier and TypeField and Description
public float
alignment

The alignment, specified as a value between 0.0 and 1.0, inclusive.

public int
maximum

The maximum size allowed.

public int
minimum

The minimum size required.

public int
preferred

The preferred (natural) size.

Constructor Summary

AccessConstructor and Description
public
SizeRequirements()

Creates a SizeRequirements object with the minimum, preferred, and maximum sizes set to zero and an alignment value of 0.5 (centered).

public
SizeRequirements(int
the minimum size >= 0
min
,
int
the preferred size >= 0
pref
,
int
the maximum size >= 0
max
,
float
the alignment >= 0.0f && <= 1.0f
a
)

Creates a SizeRequirements object with the specified minimum, preferred, and maximum sizes and the specified alignment.

Method Summary

Modifier and TypeMethod and Description
public static int[]

Returns:

an array of ints containing the final size for each item
adjustSizes
(int
an int specifying the size difference
delta
,
SizeRequirements[]
an array of SizeRequirements objects
children
)

Adjust a specified array of sizes by a given amount.

public static void
calculateAlignedPositions(int
the total span to be allocated >= 0.
allocated
,
SizeRequirements
the total of the children requests.
total
,
SizeRequirements[]
the size requirements for each component.
children
,
int[]
the offset from 0 for each child where the spans were allocated (determines placement of the span).
offsets
,
int[]
the span allocated for each child to make the total target span.
spans
)

Creates a bunch of offset/span pairs specifying how to lay out a set of components with the specified alignments.

public static void
calculateAlignedPositions(int
the total span to be allocated >= 0.
allocated
,
SizeRequirements
the total of the children requests.
total
,
SizeRequirements[]
the size requirements for each component.
children
,
int[]
the offset from 0 for each child where the spans were allocated (determines placement of the span).
offsets
,
int[]
the span allocated for each child to make the total target span.
spans
,
boolean
when true, the alignment value 0.0f means left/top; when false, it means right/bottom.
normal
)

Creates a set of offset/span pairs specifying how to lay out a set of components with the specified alignments.

public static void
calculateTiledPositions(int
the total span to be allocated >= 0.
allocated
,
SizeRequirements
the total of the children requests. This argument is optional and may be null.
total
,
SizeRequirements[]
the size requirements for each component.
children
,
int[]
the offset from 0 for each child where the spans were allocated (determines placement of the span).
offsets
,
int[]
the span allocated for each child to make the total target span.
spans
)

Creates a set of offset/span pairs representing how to lay out a set of components end-to-end.

public static void
calculateTiledPositions(int
the total span to be allocated >= 0.
allocated
,
SizeRequirements
the total of the children requests. This argument is optional and may be null.
total
,
SizeRequirements[]
the size requirements for each component.
children
,
int[]
the offset from 0 for each child where the spans were allocated (determines placement of the span).
offsets
,
int[]
the span allocated for each child to make the total target span.
spans
,
boolean
tile with offsets increasing from 0 if true and with offsets decreasing from the end of the allocated space if false.
forward
)

Creates a set of offset/span pairs representing how to lay out a set of components end-to-end.

private static void
compressedTile(int allocated, long min, long pref, long max, SizeRequirements[] request, int[] offsets, int[] spans, boolean forward)

private static void
expandedTile(int allocated, long min, long pref, long max, SizeRequirements[] request, int[] offsets, int[] spans, boolean forward)

public static SizeRequirements

Returns:

the total space requirements.
getAlignedSizeRequirements
(SizeRequirements[]
the set of child requirements. If of zero length, the returns result will be a default instance of SizeRequirements.
children
)

Determines the total space necessary to align a set of components.

public static SizeRequirements

Returns:

the total space requirements.
getTiledSizeRequirements
(SizeRequirements[]
the space requirements for a set of components. The vector may be of zero length, which will result in a default SizeRequirements object instance being passed back.
children
)

Determines the total space necessary to place a set of components end-to-end.

public String

Returns:

the string
toString
()

Overrides java.lang.Object.toString.

Returns a string describing the minimum, preferred, and maximum size requirements, along with the alignment.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

alignmentback to summary
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.

maximumback to summary
public int maximum

The maximum size allowed. For a component comp, this should be equal to either comp.getMaximumSize().width or comp.getMaximumSize().height.

minimumback to summary
public int minimum

The minimum size required. For a component comp, this should be equal to either comp.getMinimumSize().width or comp.getMinimumSize().height.

preferredback to summary
public int preferred

The preferred (natural) size. For a component comp, this should be equal to either comp.getPreferredSize().width or comp.getPreferredSize().height.

Constructor Detail

SizeRequirementsback to summary
public SizeRequirements()

Creates a SizeRequirements object with the minimum, preferred, and maximum sizes set to zero and an alignment value of 0.5 (centered).

SizeRequirementsback to summary
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.

Parameters
min:int

the minimum size >= 0

pref:int

the preferred size >= 0

max:int

the maximum size >= 0

a:float

the alignment >= 0.0f && <= 1.0f

Method Detail

adjustSizesback to summary
public static int[] adjustSizes(int delta, SizeRequirements[] children)

Adjust a specified array of sizes by a given amount.

Parameters
delta:int

an int specifying the size difference

children:SizeRequirements[]

an array of SizeRequirements objects

Returns:int[]

an array of ints containing the final size for each item

calculateAlignedPositionsback to summary
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. Normal alignment will be done with an alignment value of 0.0f representing the left/top edge of a component.

Parameters
allocated:int

the total span to be allocated >= 0.

total:SizeRequirements

the total of the children requests.

children:SizeRequirements[]

the size requirements for each component.

offsets:int[]

the offset from 0 for each child where the spans were allocated (determines placement of the span).

spans:int[]

the span allocated for each child to make the total target span.

calculateAlignedPositionsback to summary
public static void calculateAlignedPositions(int allocated, SizeRequirements total, SizeRequirements[] children, int[] offsets, int[] spans, boolean normal)

Creates a set 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. This method also requires a flag indicating whether normal or reverse alignment should be performed. With normal alignment the value 0.0f represents the left/top edge of the component to be aligned. With reverse alignment, 0.0f represents the right/bottom edge.

Parameters
allocated:int

the total span to be allocated >= 0.

total:SizeRequirements

the total of the children requests.

children:SizeRequirements[]

the size requirements for each component.

offsets:int[]

the offset from 0 for each child where the spans were allocated (determines placement of the span).

spans:int[]

the span allocated for each child to make the total target span.

normal:boolean

when true, the alignment value 0.0f means left/top; when false, it means right/bottom.

Since
1.4
calculateTiledPositionsback to summary
public static void calculateTiledPositions(int allocated, SizeRequirements total, SizeRequirements[] children, int[] offsets, int[] spans)

Creates a set 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. The components will be tiled in the forward direction with offsets increasing from 0.

Parameters
allocated:int

the total span to be allocated >= 0.

total:SizeRequirements

the total of the children requests. This argument is optional and may be null.

children:SizeRequirements[]

the size requirements for each component.

offsets:int[]

the offset from 0 for each child where the spans were allocated (determines placement of the span).

spans:int[]

the span allocated for each child to make the total target span.

calculateTiledPositionsback to summary
public static void calculateTiledPositions(int allocated, SizeRequirements total, SizeRequirements[] children, int[] offsets, int[] spans, boolean forward)

Creates a set 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. This method also requires a flag indicating whether components should be tiled in the forward direction (offsets increasing from 0) or reverse direction (offsets decreasing from the end of the allocated space). The forward direction represents components tiled from left to right or top to bottom. The reverse direction represents components tiled from right to left or bottom to top.

Parameters
allocated:int

the total span to be allocated >= 0.

total:SizeRequirements

the total of the children requests. This argument is optional and may be null.

children:SizeRequirements[]

the size requirements for each component.

offsets:int[]

the offset from 0 for each child where the spans were allocated (determines placement of the span).

spans:int[]

the span allocated for each child to make the total target span.

forward:boolean

tile with offsets increasing from 0 if true and with offsets decreasing from the end of the allocated space if false.

Since
1.4
compressedTileback to summary
private static void compressedTile(int allocated, long min, long pref, long max, SizeRequirements[] request, int[] offsets, int[] spans, boolean forward)
expandedTileback to summary
private static void expandedTile(int allocated, long min, long pref, long max, SizeRequirements[] request, int[] offsets, int[] spans, boolean forward)
getAlignedSizeRequirementsback to summary
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. The total space required will never be more than Integer.MAX_VALUE.

Parameters
children:SizeRequirements[]

the set of child requirements. If of zero length, the returns result will be a default instance of SizeRequirements.

Returns:SizeRequirements

the total space requirements.

getTiledSizeRequirementsback to summary
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). The space requirement is never more than Integer.MAX_VALUE.

Parameters
children:SizeRequirements[]

the space requirements for a set of components. The vector may be of zero length, which will result in a default SizeRequirements object instance being passed back.

Returns:SizeRequirements

the total space requirements.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string describing the minimum, preferred, and maximum size requirements, along with the alignment.

Returns:String

the string