|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.wordpress.tipsforjava.swing.RelativeLayout
public class RelativeLayout extends Object
The 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.
| Field Summary | |
|---|---|
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
|
private static int |
MINIMUM
|
private static int |
PREFERRED
|
static float |
TRAILING
|
static int |
X_AXIS
|
static int |
Y_AXIS
|
private float |
alignment
The alignment of the Components on the other axis of the Container. |
private int |
axis
The axis of the Components within the Container. |
private int |
borderGap
The gap (in pixels) used before the leading component and after the trailing component. |
private HashMap |
constraints
|
private boolean |
fill
|
private int |
fillGap
|
private int |
gap
This is the gap (in pixels) which specifies the space between components It can be changed at any time and should be a non-negative integer. |
private int |
roundingPolicy
|
| Constructor Summary | |
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 |
|
| Method Summary | |
|---|---|
void
|
addLayoutComponent(String name, Component component)
Not supported |
void
|
addLayoutComponent(Component component, Object constraint)
|
private void
|
adjustEqual(int[] relativeSpace, int spaceRemaining)
|
private void
|
adjustFirst(int[] relativeSpace, int spaceRemaining)
|
protected void
|
adjustForRounding(int[] relativeSpace, int spaceRemaining)
|
private void
|
adjustLargest(int[] relativeSpace, int spaceRemaining)
|
private void
|
adjustLast(int[] relativeSpace, int spaceRemaining)
|
private int[]
|
allocateRelativeSpace(Container parent, int spaceAvailable, float relativeTotal)
|
float
|
getAlignment()
Gets the alignment of the components on the opposite axis. |
int
|
getAxis()
Gets the layout axis. |
int
|
getBorderGap()
Gets the initial gap. |
Float
|
getConstraints(Component component)
Gets the constraints for the specified component. |
private Dimension
|
getDimension(Component component, int type)
|
int
|
getFillGap()
Gets the fill gap amount. |
int
|
getGap()
Gets the gap between components. |
float
|
getLayoutAlignmentX(Container parent)
Returns the alignment along the x axis. |
float
|
getLayoutAlignmentY(Container parent)
Returns the alignment along the y axis. |
private Dimension
|
getLayoutSize(Container parent, int type)
|
private int
|
getLocationX(Component component, int width)
|
private int
|
getLocationY(Component component, int height)
|
int
|
getRoundingPolicy()
Gets the rounding policy. |
private int
|
getVisibleComponents(Container container)
|
void
|
invalidateLayout(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(Container parent)
Lays out the specified container using this layout. |
private void
|
layoutContainerHorizontally(Container parent)
|
private void
|
layoutContainerVertically(Container parent)
|
Dimension
|
maximumLayoutSize(Container target)
There is no maximum. |
Dimension
|
minimumLayoutSize(Container parent)
Determines the minimum size of the container argument using this column layout. |
Dimension
|
preferredLayoutSize(Container parent)
Determines the preferred size of the container argument using this column layout. |
void
|
removeLayoutComponent(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. |
String
|
toString()
Returns the string representation of this column layout's values. |
| Methods inherited from class Object | |
|---|---|
| wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
| Field Detail |
|---|
public static final float CENTER
public static final float COMPONENT
public static final int DO_NOTHING
public static final int EQUAL
public static final int FIRST
public static final int LARGEST
public static final int LAST
public static final float LEADING
private static final int MINIMUM
private static final int PREFERRED
public static final float TRAILING
public static final int X_AXIS
public static final int Y_AXIS
private float alignment
private int axis
private int borderGap
private HashMap constraints
private boolean fill
private int fillGap
private int gap
private int roundingPolicy
| Constructor Detail |
|---|
public RelativeLayout()
public RelativeLayout(int axis)
axis - X-AXIS or Y_AXIS
public RelativeLayout(int axis, int gap)
All RelativeLayout constructors defer to this one.
axis - X-AXIS or Y_AXISgap - the gap
| Method Detail |
|---|
public void addLayoutComponent(String name, Component component)
public void addLayoutComponent(Component component, Object constraint)
private void adjustEqual(int[] relativeSpace, int spaceRemaining)
private void adjustFirst(int[] relativeSpace, int spaceRemaining)
protected void adjustForRounding(int[] relativeSpace, int spaceRemaining)
private void adjustLargest(int[] relativeSpace, int spaceRemaining)
private void adjustLast(int[] relativeSpace, int spaceRemaining)
private int[] allocateRelativeSpace(Container parent, int spaceAvailable, float relativeTotal)
public float getAlignment()
public int getAxis()
public int getBorderGap()
public Float getConstraints(Component component)
component - the component to be queried
private Dimension getDimension(Component component, int type)
public int getFillGap()
public int getGap()
public float getLayoutAlignmentX(Container parent)
public float getLayoutAlignmentY(Container parent)
private Dimension getLayoutSize(Container parent, int type)
private int getLocationX(Component component, int width)
private int getLocationY(Component component, int height)
public int getRoundingPolicy()
private int getVisibleComponents(Container container)
public void invalidateLayout(Container target)
public boolean isFill()
public void layoutContainer(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.
target - the container in which to do the layout
private void layoutContainerHorizontally(Container parent)
private void layoutContainerVertically(Container parent)
public Dimension maximumLayoutSize(Container target)
public Dimension minimumLayoutSize(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.
target - the container in which to do the layout
public Dimension preferredLayoutSize(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.
target - the container in which to do the layout
public void removeLayoutComponent(Component comp)
comp - the component to be removed
public void setAlignment(float alignment)
public void setAxis(int axis)
axis - the layout axis
public void setBorderGap(int borderGap)
borderGap - the leading/trailing gap
public void setFill(boolean fill)
public void setFillGap(int fillGap)
public void setGap(int gap)
gap - the gap between components
public void setRoundingPolicy(int roundingPolicy)
public String toString()
Groovy Documentation