LayoutStyle (Java Platform SE 6) (original) (raw)
javax.swing
Class LayoutStyle
java.lang.Object
javax.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 aLayoutStyle
. Instead use the static methodgetInstance
to obtain the current instance.
Since:
1.6
Nested Class Summary | |
---|---|
static class | LayoutStyle.ComponentPlacement ComponentPlacement is an enumeration of the possible ways two components can be placed relative to each other. |
Constructor Summary |
---|
LayoutStyle() Creates a new LayoutStyle. |
Method Summary | |
---|---|
abstract int | [getContainerGap](../../javax/swing/LayoutStyle.html#getContainerGap%28javax.swing.JComponent, int, java.awt.Container%29)(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() Returns the shared instance of LayoutStyle. |
abstract int | [getPreferredGap](../../javax/swing/LayoutStyle.html#getPreferredGap%28javax.swing.JComponent, javax.swing.JComponent, javax.swing.LayoutStyle.ComponentPlacement, int, java.awt.Container%29)(JComponent component1,JComponent component2,LayoutStyle.ComponentPlacement type, int position,Container parent) Returns the amount of space to use between two components. |
static void | setInstance(LayoutStyle style) Sets the shared instance of LayoutStyle. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, [wait](../../java/lang/Object.html#wait%28long, int%29) |
Constructor Detail |
---|
LayoutStyle
public LayoutStyle()
Creates a new LayoutStyle
. You generally don't create a LayoutStyle
. Instead use the methodgetInstance
to obtain the currentLayoutStyle
.
Method Detail |
---|
setInstance
public static void setInstance(LayoutStyle style)
Sets the shared instance of LayoutStyle
. Specifyingnull
results in using the LayoutStyle
from the current LookAndFeel
.
Parameters:
style
- the LayoutStyle
, or null
See Also:
getInstance
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:
the shared instance of LayoutStyle
See Also:
getPreferredGap
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 placecomponent2
relative to component1
. For example, the following returns the amount of space to place between component2
and component1
when component2
is placed vertically abovecomponent1
:
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
andUNRELATED
types.
The return value is not intended to take into account the current size and position of component2
orcomponent1
. 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
position
- the position component2
is being placed relative to component1
; one ofSwingConstants.NORTH
,SwingConstants.SOUTH
,SwingConstants.EAST
orSwingConstants.WEST
type
- how the two components are being placed
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
Throws:
[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")
- if component1
,component2
or type
isnull
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if position
is not one of SwingConstants.NORTH
,SwingConstants.SOUTH
,SwingConstants.EAST
or SwingConstants.WEST
Since:
1.6
See Also:
getContainerGap
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
- the JComponent
being positioned
position
- the position component
is being placed relative to its parent; one ofSwingConstants.NORTH
,SwingConstants.SOUTH
,SwingConstants.EAST
orSwingConstants.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
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if position
is not one of SwingConstants.NORTH
,SwingConstants.SOUTH
,SwingConstants.EAST
or SwingConstants.WEST
Submit a bug or feature
For further API reference and developer documentation, see Java SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2015, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
Scripting on this page tracks web page traffic, but does not change the content in any way.