FileDocCategorySizeDatePackage
LayoutStyle.javaAPI DocJava SE 6 API8416Tue Jun 10 00:26:40 BST 2008javax.swing

LayoutStyle

public abstract class LayoutStyle extends Object
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.

version
1.2, 11/17/05
since
1.6

Fields Summary
Constructors Summary
public LayoutStyle()
Creates a new LayoutStyle. You generally don't create a LayoutStyle. Instead use the method getInstance to obtain the current LayoutStyle.

    
Methods Summary
public abstract intgetContainerGap(javax.swing.JComponent component, int position, java.awt.Container parent)
Returns the amount of space to place between the component and specified edge of its parent.

param
component the JComponent being positioned
param
position the position component is being placed relative to its parent; one of SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST
param
parent the parent of component; this may differ from the actual parent and may be null
return
the amount of space to place between the component and specified edge
throws
IllegalArgumentException if position is not one of SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST

public static javax.swing.LayoutStylegetInstance()
Returns the shared instance of LayoutStyle. If an instance has not been specified in setInstance, this will return the LayoutStyle from the current LookAndFeel.

see
LookAndFeel#getLayoutStyle
return
the shared instance of LayoutStyle

        LayoutStyle style;
        synchronized(LayoutStyle.class) {
            style = (LayoutStyle)AppContext.getAppContext().
                    get(LayoutStyle.class);
        }
        if (style == null) {
            return UIManager.getLookAndFeel().getLayoutStyle();
        }
        return style;
    
public abstract intgetPreferredGap(javax.swing.JComponent component1, javax.swing.JComponent component2, javax.swing.LayoutStyle$ComponentPlacement type, int position, java.awt.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.

param
component1 the JComponent component2 is being placed relative to
param
component2 the JComponent being placed
param
position the position component2 is being placed relative to component1; one of SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST
param
type how the two components are being placed
param
parent the parent of component2; this may differ from the actual parent and it may be null
return
the amount of space to place between the two components
throws
NullPointerException if component1, component2 or type is null
throws
IllegalArgumentException if position is not one of SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST
see
LookAndFeel#getLayoutStyle
since
1.6

public static voidsetInstance(javax.swing.LayoutStyle style)
Sets the shared instance of LayoutStyle. Specifying null results in using the LayoutStyle from the current LookAndFeel.

param
style the LayoutStyle, or null
see
#getInstance

        synchronized(LayoutStyle.class) {
            if (style == null) {
                AppContext.getAppContext().remove(LayoutStyle.class);
            }
            else {
                AppContext.getAppContext().put(LayoutStyle.class, style);
            }
        }