Class 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.
- Since:
- 1.6
Nested Class Summary
| Modifier and Type | Class | Description |
|---|---|---|
static enum |
LayoutStyle.ComponentPlacement |
ComponentPlacement is an enumeration of the possible ways two components can be placed relative to each other. |
Constructor Summary
| Constructor | Description |
|---|---|
LayoutStyle() |
Creates a new LayoutStyle. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
abstract int |
getContainerGap |
Returns the amount of space to place between the component and specified edge of its parent. |
static LayoutStyle |
getInstance() |
Returns the shared instance of LayoutStyle. |
abstract int |
getPreferredGap |
Returns the amount of space to use between two components. |
static void |
setInstance |
Sets the shared instance of LayoutStyle. |
Constructor Details
LayoutStyle
public LayoutStyle()
LayoutStyle. You generally don't create a LayoutStyle. Instead use the method getInstance to obtain the current LayoutStyle.Method Details
setInstance
public static void setInstance(LayoutStyle style)
LayoutStyle. Specifying null results in using the LayoutStyle from the current LookAndFeel.- Parameters:
-
style- theLayoutStyle, ornull - See Also:
getInstance
public static LayoutStyle getInstance()
LayoutStyle. If an instance has not been specified in setInstance, this will return the LayoutStyle from the current LookAndFeel.- Returns:
- the shared instance of
LayoutStyle - See Also:
getPreferredGap
public abstract int getPreferredGap(JComponent component1, JComponent component2, LayoutStyle.ComponentPlacement type, int position, Container parent)
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- theJComponentcomponent2is being placed relative to -
component2- theJComponentbeing placed -
position- the positioncomponent2is being placed relative tocomponent1; one ofSwingConstants.NORTH,SwingConstants.SOUTH,SwingConstants.EASTorSwingConstants.WEST -
type- how the two components are being placed -
parent- the parent ofcomponent2; this may differ from the actual parent and it may benull - Returns:
- the amount of space to place between the two components
- Throws:
-
NullPointerException- ifcomponent1,component2ortypeisnull -
IllegalArgumentException- ifpositionis not one ofSwingConstants.NORTH,SwingConstants.SOUTH,SwingConstants.EASTorSwingConstants.WEST - Since:
- 1.6
- See Also:
getContainerGap
public abstract int getContainerGap(JComponent component, int position, Container parent)
- Parameters:
-
component- theJComponentbeing positioned -
position- the positioncomponentis being placed relative to its parent; one ofSwingConstants.NORTH,SwingConstants.SOUTH,SwingConstants.EASTorSwingConstants.WEST -
parent- the parent ofcomponent; this may differ from the actual parent and may benull - Returns:
- the amount of space to place between the component and specified edge
- Throws:
-
IllegalArgumentException- ifpositionis not one ofSwingConstants.NORTH,SwingConstants.SOUTH,SwingConstants.EASTorSwingConstants.WEST
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/LayoutStyle.html