public class LayoutStyle extends Object
RELATED
).
This class is primarily useful for JREs prior to 1.6. In 1.6 API for this was added to Swing. When run on a JRE of 1.6 or greater this will call into the appropriate methods in Swing.
Modifier and Type | Field and Description |
---|---|
static int |
INDENT
Possible argument to getPreferredGap.
|
static int |
RELATED
Possible argument to getPreferredGap.
|
static int |
UNRELATED
Possible argument to getPreferredGap.
|
Constructor and Description |
---|
LayoutStyle() |
Modifier and Type | Method and Description |
---|---|
int |
getContainerGap(Component component,
int position,
Container parent)
Returns the amount of space to position a component inside its
parent.
|
int |
getPreferredGap(Component component1,
Component component2,
int type,
int position,
Container parent)
Returns the amount of space to use between two components.
|
static LayoutStyle |
getSharedInstance()
Factory methods for obtaining the current
LayoutStyle
object appropriate for the current look and feel. |
static void |
setSharedInstance(LayoutStyle layout)
Sets the LayoutStyle instance to use for this look and feel.
|
public static final int RELATED
public static final int UNRELATED
public static final int INDENT
INDENT
constant for this.
For example, to indent a check box relative to a label use this
constant to getPreferredGap
.public static void setSharedInstance(LayoutStyle layout)
layout
- the LayoutStyle to use; a value of null indicates
the default should be usedpublic static LayoutStyle getSharedInstance()
LayoutStyle
object appropriate for the current look and feel.public int getPreferredGap(Component component1, Component component2, int 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, LayoutStyle.RELATED, SwingConstants.NORTH, parent);The
type
parameter indicates the type
of gap being requested. It can be one of the following values:
RELATED
| If the two components will be contained in
the same parent and are showing similar logically related
items, use RELATED .
|
UNRELATED
| If the two components will be
contained in the same parent but show logically unrelated items
use UNRELATED .
|
INDENT
| Used to obtain the preferred distance to indent a component
relative to another. For example, if you want to horizontally
indent a JCheckBox relative to a JLabel use INDENT .
This is only useful for the horizontal axis.
|
It's important to note that some look and feels may not distinguish
between RELATED
and UNRELATED
.
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.
component1
- the JComponent
component2
is being placed relative tocomponent2
- the JComponent
being placedtype
- how the two components are being placedposition
- 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 may be nullIllegalArgumentException
- if position
is not
one of SwingConstants.NORTH
,
SwingConstants.SOUTH
,
SwingConstants.EAST
or
SwingConstants.WEST
; type
not one
of INDENT
, RELATED
or UNRELATED
; or component1
or
component2
is nullpublic int getContainerGap(Component component, int position, Container parent)
component
- the Component
being positionedposition
- 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 nullIllegalArgumentException
- if position
is not
one of SwingConstants.NORTH
,
SwingConstants.SOUTH
,
SwingConstants.EAST
or
SwingConstants.WEST
;
or component
is null