public class

DefaultLayoutStyle

extends LayoutStyle
java.lang.Object
   ↳ javax.swing.LayoutStyle
     ↳ sun.swing.DefaultLayoutStyle

Class Overview

An implementation of LayoutStyle that returns 6 for related components, otherwise 12. This class also provides helper methods for subclasses.

Summary

Public Constructors
DefaultLayoutStyle()
Public Methods
int getButtonGap(JComponent c, int position)
If c is a check box or radio button, and the border is not painted this returns the inset along the specified axis.
int getContainerGap(JComponent component, int position, Container parent)
Returns the amount of space to place between the component and specified edge of its parent.
static LayoutStyle getInstance()
int getPreferredGap(JComponent component1, JComponent component2, LayoutStyle.ComponentPlacement type, int position, Container parent)
Returns the amount of space to use between two components.
Protected Methods
int flipDirection(int position)
int getButtonGap(JComponent source, JComponent target, int position, int offset)
For some look and feels check boxs and radio buttons typically don't paint the border, yet they have padding for a border.
int getButtonGap(JComponent source, int position, int offset)
For some look and feels check boxs and radio buttons typically don't paint the border, yet they have padding for a border.
int getIndent(JComponent c, int position)
Returns the amount to indent the specified component if it's a JCheckBox or JRadioButton.
boolean isLabelAndNonlabel(JComponent c1, JComponent c2, int position)
Returns true if the classes identify a JLabel and a non-JLabel along the horizontal axis.
[Expand]
Inherited Methods
From class javax.swing.LayoutStyle
From class java.lang.Object

Public Constructors

public DefaultLayoutStyle ()

Public Methods

public int getButtonGap (JComponent c, int position)

If c is a check box or radio button, and the border is not painted this returns the inset along the specified axis.

public 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 the JComponent being positioned
position the position component is being placed relative to its parent; one of SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST
parent the parent of component; this may differ from the actual parent and may be null
Returns
  • the amount of space to place between the component and specified edge

public static LayoutStyle getInstance ()

public 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 the JComponent component2 is being placed relative to
component2 the JComponent being placed
type how the two components are being placed
position the position component2 is being placed relative to component1; one of SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST
parent the parent of component2; this may differ from the actual parent and it may be null
Returns
  • the amount of space to place between the two components

Protected Methods

protected int flipDirection (int position)

protected int getButtonGap (JComponent source, JComponent target, int position, int offset)

For some look and feels check boxs and radio buttons typically don't paint the border, yet they have padding for a border. Look and feel guidelines generally don't include this space. Use this method to subtract this space from the specified components.

Parameters
source First component
target Second component
position Position doing layout along.
offset Ideal offset, not including border/margin
Returns
  • offset - border/margin around the component.

protected int getButtonGap (JComponent source, int position, int offset)

For some look and feels check boxs and radio buttons typically don't paint the border, yet they have padding for a border. Look and feel guidelines generally don't include this space. Use this method to subtract this space from the specified components.

Parameters
source Component
position Position doing layout along.
offset Ideal offset, not including border/margin
Returns
  • offset - border/margin around the component.

protected int getIndent (JComponent c, int position)

Returns the amount to indent the specified component if it's a JCheckBox or JRadioButton. If the component is not a JCheckBox or JRadioButton, 0 will be returned.

protected boolean isLabelAndNonlabel (JComponent c1, JComponent c2, int position)

Returns true if the classes identify a JLabel and a non-JLabel along the horizontal axis.