Top Description Inners Constructors Methods
javax.swing

public abstract Class LayoutStyle

extends Object
Class Inheritance
Known Direct Subclasses
sun.swing.DefaultLayoutStyle
Imports
java.awt.Container, javax.swing.plaf.ComponentUI, sun.awt.AppContext

LayoutStyle provides information about how to position components. This class is primarily useful for visual tools and layout managers. Most developers will not need to use this class.

You typically don't set or create a LayoutStyle. Instead use the static method getInstance to obtain the current instance.

Since
1.6

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
LayoutStyle.ComponentPlacement

ComponentPlacement is an enumeration of the possible ways two components can be placed relative to each other.

Constructor Summary

AccessConstructor and Description
public
LayoutStyle()

Creates a new LayoutStyle.

Method Summary

Modifier and TypeMethod and Description
public abstract int

Returns:

the amount of space to place between the component and specified edge
getContainerGap
(JComponent
the JComponent being positioned
component
,
int
the position component is being placed relative to its parent; one of SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST
position
,
Container
the parent of component; this may differ from the actual parent and may be null
parent
)

Returns the amount of space to place between the component and specified edge of its parent.

public static LayoutStyle

Returns:

the shared instance of LayoutStyle
getInstance
()

Returns the shared instance of LayoutStyle.

public abstract int

Returns:

the amount of space to place between the two components
getPreferredGap
(JComponent
the JComponent component2 is being placed relative to
component1
,
JComponent
the JComponent being placed
component2
,
LayoutStyle.ComponentPlacement
how the two components are being placed
type
,
int
the position component2 is being placed relative to component1; one of SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST
position
,
Container
the parent of component2; this may differ from the actual parent and it may be null
parent
)

Returns the amount of space to use between two components.

public static void
setInstance(LayoutStyle
the LayoutStyle, or null
style
)

Sets the shared instance of LayoutStyle.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

LayoutStyleback to summary
public LayoutStyle()

Creates a new LayoutStyle. You generally don't create a LayoutStyle. Instead use the method getInstance to obtain the current LayoutStyle.

Method Detail

getContainerGapback to summary
public abstract int getContainerGap(JComponent component, int position, Container parent)

Returns the amount of space to place between the component and specified edge of its parent.

Parameters
component:JComponent

the JComponent being positioned

position:int

the position component is being placed relative to its parent; one of SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST

parent:Container

the parent of component; this may differ from the actual parent and may be null

Returns:int

the amount of space to place between the component and specified edge

Exceptions
IllegalArgumentException:
if position is not one of SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST
getInstanceback to summary
public static LayoutStyle getInstance()

Returns the shared instance of LayoutStyle. If an instance has not been specified in setInstance, this will return the LayoutStyle from the current LookAndFeel.

Returns:LayoutStyle

the shared instance of LayoutStyle

See Also
LookAndFeel#getLayoutStyle
getPreferredGapback to summary
public abstract int getPreferredGap(JComponent component1, JComponent component2, LayoutStyle.ComponentPlacement type, int position, Container parent)

Returns the amount of space to use between two components. The return value indicates the distance to place component2 relative to component1. For example, the following returns the amount of space to place between component2 and component1 when component2 is placed vertically above component1:

  int gap = getPreferredGap(component1, component2,
                            ComponentPlacement.RELATED,
                            SwingConstants.NORTH, parent);
The type parameter indicates the relation between the two components. If the two components will be contained in the same parent and are showing similar logically related items, use RELATED. If the two components will be contained in the same parent but show logically unrelated items use UNRELATED. Some look and feels may not distinguish between the RELATED and UNRELATED types.

The return value is not intended to take into account the current size and position of component2 or component1. 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:JComponent

the JComponent component2 is being placed relative to

component2:JComponent

the JComponent being placed

type:LayoutStyle.ComponentPlacement

how the two components are being placed

position:int

the position component2 is being placed relative to component1; one of SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST

parent:Container

the parent of component2; this may differ from the actual parent and it may be null

Returns:int

the amount of space to place between the two components

Exceptions
NullPointerException:
if component1, component2 or type is null
IllegalArgumentException:
if position is not one of SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST
Since
1.6
See Also
LookAndFeel#getLayoutStyle
setInstanceback to summary
public static void setInstance(LayoutStyle style)

Sets the shared instance of LayoutStyle. Specifying null results in using the LayoutStyle from the current LookAndFeel.

Parameters
style:LayoutStyle

the LayoutStyle, or null

See Also
getInstance
javax.swing back to summary

public final Enum LayoutStyle.ComponentPlacement

extends Enum<LayoutStyle.ComponentPlacement>
Class Inheritance

ComponentPlacement is an enumeration of the possible ways two components can be placed relative to each other. ComponentPlacement is used by the LayoutStyle method getPreferredGap. Refer to LayoutStyle for more information.
Since
1.6
See Also
LayoutStyle#getPreferredGap(JComponent, JComponent, ComponentPlacement, int, Container)

Field Summary

Modifier and TypeField and Description
public static final LayoutStyle.ComponentPlacement
INDENT

Enumeration value indicating the distance to indent a component is being requested.

public static final LayoutStyle.ComponentPlacement
RELATED

Enumeration value indicating the two components are visually related and will be placed in the same parent.

public static final LayoutStyle.ComponentPlacement
UNRELATED

Enumeration value indicating the two components are visually unrelated and will be placed in the same parent.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static LayoutStyle.ComponentPlacement
public static LayoutStyle.ComponentPlacement[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

INDENTback to summary
public static final LayoutStyle.ComponentPlacement INDENT

Enumeration value indicating the distance to indent a component is being requested. For example, often times the children of a label will be horizontally indented from the label. To determine the preferred distance for such a gap use the INDENT type.

This value is typically only useful with a direction of EAST or WEST.

RELATEDback to summary
public static final LayoutStyle.ComponentPlacement RELATED

Enumeration value indicating the two components are visually related and will be placed in the same parent. For example, a JLabel providing a label for a JTextField is typically visually associated with the JTextField; the constant RELATED is used for this.

UNRELATEDback to summary
public static final LayoutStyle.ComponentPlacement UNRELATED

Enumeration value indicating the two components are visually unrelated and will be placed in the same parent. For example, groupings of components are usually visually separated; the constant UNRELATED is used for this.

Constructor Detail

ComponentPlacementback to summary
private ComponentPlacement()

Method Detail

valueOfback to summary
public static LayoutStyle.ComponentPlacement valueOf(String name)
valuesback to summary
public static LayoutStyle.ComponentPlacement[] values()