Class LayoutStyle
LayoutStyle is used to determine how much space to place between components
during layout. LayoutStyle can be obtained for two components, or for
a component relative to an edge of a parent container. The amount of
space can vary depending upon whether or not the components are
logically grouped together (RELATED).
This class is primarily useful for JREs prior to 1.6. In 1.6 API for this was added to Swing. When run on a JRE of 1.6 or greater this will call into the appropriate methods in Swing.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetContainerGap(Component component, int position, Container parent) Returns the amount of space to position a component inside its parent.intgetPreferredGap(Component component1, Component component2, int type, int position, Container parent) Returns the amount of space to use between two components.static LayoutStyleFactory methods for obtaining the currentLayoutStyleobject appropriate for the current look and feel.static voidsetSharedInstance(LayoutStyle layout) Sets the LayoutStyle instance to use for this look and feel.
-
Field Details
-
RELATED
public static final int RELATEDPossible argument to getPreferredGap. Used to indicate the two components are grouped together.- See Also:
-
UNRELATED
public static final int UNRELATEDPossible argument to getPreferredGap. Used to indicate the two components are not grouped together.- See Also:
-
INDENT
public static final int INDENTPossible argument to getPreferredGap. Used to indicate the distance to indent a component is being requested. To visually indicate a set of related components they will often times be horizontally indented, theINDENTconstant for this. For example, to indent a check box relative to a label use this constant togetPreferredGap.- See Also:
-
-
Constructor Details
-
LayoutStyle
public LayoutStyle()
-
-
Method Details
-
getPreferredGap
public int getPreferredGap(Component component1, Component component2, int type, int position, Container parent) Returns the amount of space to use between two components. The return value indicates the distance to place
component2relative tocomponent1. For example, the following returns the amount of space to place betweencomponent2andcomponent1whencomponent2is placed vertically abovecomponent1:int gap = getPreferredGap(component1, component2, LayoutStyle.RELATED, SwingConstants.NORTH, parent);The
typeparameter indicates the type of gap being requested. It can be one of the following values:RELATEDIf the two components will be contained in the same parent and are showing similar logically related items, useRELATED.UNRELATEDIf the two components will be contained in the same parent but show logically unrelated items useUNRELATED.INDENTUsed to obtain the preferred distance to indent a component relative to another. For example, if you want to horizontally indent a JCheckBox relative to a JLabel useINDENT. This is only useful for the horizontal axis.It's important to note that some look and feels may not distinguish between
RELATEDandUNRELATED.The return value is not intended to take into account the current size and position of
component2orcomponent1. The return value may take into consideration various properties of the components. For example, the space may vary based on font size, or the preferred size of the component.Parameters
-
component1: @param component1 theJComponentcomponent2is being placed relative to -
component2: theJComponentbeing placed -
type: how the two components are being placed -
position: @param position the positioncomponent2is being placed relative tocomponent1; one ofSwingConstants.NORTH,SwingConstants.SOUTH,SwingConstants.EASTorSwingConstants.WEST -
parent: @param parent the parent ofcomponent2; this may differ from the actual parent and may be null
Returns
the amount of space to place between the two components
Throws
IllegalArgumentException: @throws IllegalArgumentException ifpositionis not one ofSwingConstants.NORTH,SwingConstants.SOUTH,SwingConstants.EASTorSwingConstants.WEST;typenot one ofINDENT,RELATEDorUNRELATED; orcomponent1orcomponent2is null
-
-
getContainerGap
Returns the amount of space to position a component inside its parent.
Parameters
-
component: theComponentbeing positioned -
position: @param position the positioncomponentis being placed relative to its parent; one ofSwingConstants.NORTH,SwingConstants.SOUTH,SwingConstants.EASTorSwingConstants.WEST -
parent: @param parent the parent ofcomponent; this may differ from the actual parent and may be null
Returns
- Returns:
the amount of space to place between the component and specified edge
Throws
IllegalArgumentException: @throws IllegalArgumentException ifpositionis not one ofSwingConstants.NORTH,SwingConstants.SOUTH,SwingConstants.EASTorSwingConstants.WEST; orcomponentis null
-