public class RelativeLayout
extends java.lang.Object
implements java.awt.LayoutManager2, java.io.Serializable
RelativeLayout
class is a layout manager that
lays out a container's components on the specified X or Y axis.
Components can be layed out at their preferred size or at a
relative size. When relative sizing is used the component must be added
to the container using a relative size constraint, which is simply a
Float value.
The space available for relative sized components is determined by
subtracting the preferred size of the other components from the space
available in the container. Each component is then assigned a size
based on its relative size value. For example:
container.add(component1, new Float(1));
container.add(component2, new Float(2));
There is a total of 3 relative units. If the container has 300 pixels
of space available then component1 will get 100 and component2, 200.
It is possible that rounding errors will occur in which case you can
specify a rounding policy to use to allocate the extra pixels.
By defaults components are center aligned on the secondary axis
however this can be changed at the container or component level.Modifier and Type | Field and Description |
---|---|
static float |
CENTER |
static float |
COMPONENT |
static int |
DO_NOTHING |
static int |
EQUAL |
static int |
FIRST |
static int |
LARGEST |
static int |
LAST |
static float |
LEADING |
static float |
TRAILING |
static int |
X_AXIS |
static int |
Y_AXIS |
Constructor and Description |
---|
RelativeLayout()
Creates a relative layout with the components layed out on the X-Axis
using the default gap
|
RelativeLayout(int axis)
Creates a relative layout with the components layed out on the specified
axis using the default gap
|
RelativeLayout(int axis,
int gap)
Creates a relative layout with the components layed out on the specified
axis using the specfied gap
|
Modifier and Type | Method and Description |
---|---|
void |
addLayoutComponent(java.awt.Component component,
java.lang.Object constraint) |
void |
addLayoutComponent(java.lang.String name,
java.awt.Component component)
Not supported
|
protected void |
adjustForRounding(int[] relativeSpace,
int spaceRemaining) |
float |
getAlignment()
Gets the alignment of the components on the opposite axis.
|
int |
getAxis()
Gets the layout axis.
|
int |
getBorderGap()
Gets the initial gap.
|
java.lang.Float |
getConstraints(java.awt.Component component)
Gets the constraints for the specified component.
|
int |
getFillGap()
Gets the fill gap amount.
|
int |
getGap()
Gets the gap between components.
|
float |
getLayoutAlignmentX(java.awt.Container parent)
Returns the alignment along the x axis.
|
float |
getLayoutAlignmentY(java.awt.Container parent)
Returns the alignment along the y axis.
|
int |
getRoundingPolicy()
Gets the rounding policy.
|
void |
invalidateLayout(java.awt.Container target)
Invalidates the layout, indicating that if the layout manager
has cached information it should be discarded.
|
boolean |
isFill()
Gets the fill property for the component size on the opposite edge.
|
void |
layoutContainer(java.awt.Container parent)
Lays out the specified container using this layout.
|
java.awt.Dimension |
maximumLayoutSize(java.awt.Container target)
There is no maximum.
|
java.awt.Dimension |
minimumLayoutSize(java.awt.Container parent)
Determines the minimum size of the container argument using this
column layout.
|
java.awt.Dimension |
preferredLayoutSize(java.awt.Container parent)
Determines the preferred size of the container argument using
this column layout.
|
void |
removeLayoutComponent(java.awt.Component comp)
Removes the specified component from the layout.
|
void |
setAlignment(float alignment) |
void |
setAxis(int axis)
Sets the layout axis
|
void |
setBorderGap(int borderGap)
Sets the initial gap.
|
void |
setFill(boolean fill)
Change size of relative components to fill the space available
For X-AXIS aligned components the height will be filled.
|
void |
setFillGap(int fillGap)
Specify the number of pixels by which the fill size is decreased when
setFill(true) has been specified.
|
void |
setGap(int gap)
Sets the gap between components to the specified value.
|
void |
setRoundingPolicy(int roundingPolicy)
Specify the rounding policy to be used when all the avialable pixels
have not been allocated to a component.
|
java.lang.String |
toString()
Returns the string representation of this column layout's values.
|
public static final int X_AXIS
public static final int Y_AXIS
public static final float LEADING
public static final float CENTER
public static final float TRAILING
public static final float COMPONENT
public static final int DO_NOTHING
public static final int FIRST
public static final int LAST
public static final int LARGEST
public static final int EQUAL
public RelativeLayout()
public RelativeLayout(int axis)
axis
- X-AXIS or Y_AXISpublic RelativeLayout(int axis, int gap)
All RelativeLayout
constructors defer to this one.
axis
- X-AXIS or Y_AXISgap
- the gappublic int getAxis()
public void setAxis(int axis)
axis
- the layout axispublic int getGap()
public void setGap(int gap)
gap
- the gap between componentspublic int getBorderGap()
public void setBorderGap(int borderGap)
borderGap
- the leading/trailing gappublic float getAlignment()
public void setAlignment(float alignment)
public boolean isFill()
public void setFill(boolean fill)
public int getFillGap()
public void setFillGap(int fillGap)
public int getRoundingPolicy()
public void setRoundingPolicy(int roundingPolicy)
public java.lang.Float getConstraints(java.awt.Component component)
component
- the component to be queriedpublic void addLayoutComponent(java.lang.String name, java.awt.Component component)
addLayoutComponent
in interface java.awt.LayoutManager
public void addLayoutComponent(java.awt.Component component, java.lang.Object constraint)
addLayoutComponent
in interface java.awt.LayoutManager2
public void removeLayoutComponent(java.awt.Component comp)
removeLayoutComponent
in interface java.awt.LayoutManager
comp
- the component to be removedpublic java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
The preferred width of a column layout is the largest preferred width of each column in the container, plus the horizontal padding times the number of columns minus one, plus the left and right insets of the target container.
The preferred height of a column layout is the largest preferred height of each row in the container, plus the vertical padding times the number of rows minus one, plus the top and bottom insets of the target container.
preferredLayoutSize
in interface java.awt.LayoutManager
target
- the container in which to do the layoutjava.awt.RelativeLayout#minimumLayoutSize
,
Container.getPreferredSize()
public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
The minimum width of a grid layout is the largest minimum width of each column in the container, plus the horizontal padding times the number of columns minus one, plus the left and right insets of the target container.
The minimum height of a column layout is the largest minimum height of each row in the container, plus the vertical padding times the number of rows minus one, plus the top and bottom insets of the target container.
minimumLayoutSize
in interface java.awt.LayoutManager
target
- the container in which to do the layoutjava.awt.RelativeLayout#preferredLayoutSize
,
Container.doLayout()
public void layoutContainer(java.awt.Container parent)
This method reshapes the components in the specified target
container in order to satisfy the constraints of the
RelativeLayout
object.
The grid layout manager determines the size of individual components by dividing the free space in the container into equal-sized portions according to the number of rows and columns in the layout. The container's free space equals the container's size minus any insets and any specified horizontal or vertical gap. All components in a grid layout are given the same size.
layoutContainer
in interface java.awt.LayoutManager
target
- the container in which to do the layoutContainer
,
Container.doLayout()
protected void adjustForRounding(int[] relativeSpace, int spaceRemaining)
public java.awt.Dimension maximumLayoutSize(java.awt.Container target)
maximumLayoutSize
in interface java.awt.LayoutManager2
public float getLayoutAlignmentX(java.awt.Container parent)
getLayoutAlignmentX
in interface java.awt.LayoutManager2
public float getLayoutAlignmentY(java.awt.Container parent)
getLayoutAlignmentY
in interface java.awt.LayoutManager2
public void invalidateLayout(java.awt.Container target)
invalidateLayout
in interface java.awt.LayoutManager2
public java.lang.String toString()
toString
in class java.lang.Object