JComponentPack 1.5.0

com.zfqjava.swing
Class GridLayout2

java.lang.Object
  extended by com.zfqjava.swing.GridLayout2
All Implemented Interfaces:
LayoutManager, LayoutManager2, Serializable

public class GridLayout2
extends Object
implements LayoutManager2, Serializable

GridLayout2 provides a layout and it's behavior as same as java.awt.GridLayout, but it has features to use component preferrred size and minimum size.

See Also:
Serialized Form

Constructor Summary
GridLayout2()
          Creates a grid layout with a default of one column per component, in a single row.
GridLayout2(int rows, int cols)
          Creates a grid layout with the specified number of rows and columns.
GridLayout2(int rows, int cols, int hgap, int vgap)
          Creates a grid layout with the specified number of rows and columns.
 
Method Summary
 void addLayoutComponent(Component comp, Object constraints)
          Adds the specified component to the layout, using the specified constraint object.
 void addLayoutComponent(String name, Component comp)
          If the layout manager uses a per-component string, adds the component comp to the layout, associating it with the string specified by name.
 int getColumns()
          Gets the number of columns in this layout.
 int getHgap()
          Gets the horizontal 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.
 int getRows()
          Gets the number of rows in this layout.
 int getVgap()
          Gets the vertical gap between components.
 void invalidateLayout(Container parent)
          Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
 void layoutContainer(Container parent)
          Lays out the specified container.
 Dimension maximumLayoutSize(Container parent)
          Calculates the maximum size dimensions for the specified container, given the components it contains.
 Dimension minimumLayoutSize(Container parent)
          Calculates the minimum size dimensions for the specified container, given the components it contains.
 Dimension preferredLayoutSize(Container parent)
          Calculates the preferred size dimensions for the specified container, given the components it contains.
 void removeLayoutComponent(Component comp)
          Removes the specified component from the layout.
 void setColumns(int cols)
          Sets the number of columns in this layout to the specified value.
 void setHgap(int hgap)
          Sets the horizontal gap between components to the specified value.
 void setRows(int rows)
          Sets the number of rows in this layout to the specified value.
 void setVgap(int vgap)
          Sets the vertical gap between components to the specified value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridLayout2

public GridLayout2()
Creates a grid layout with a default of one column per component, in a single row.


GridLayout2

public GridLayout2(int rows,
                   int cols)
Creates a grid layout with the specified number of rows and columns. All components in the layout are given equal size.

One, but not both, of rows and cols can be zero, which means that any number of objects can be placed in a row or in a column.

Parameters:
rows - the rows, with the value zero meaning any number of rows.
cols - the columns, with the value zero meaning any number of columns.

GridLayout2

public GridLayout2(int rows,
                   int cols,
                   int hgap,
                   int vgap)
Creates a grid layout with the specified number of rows and columns. All components in the layout are given equal size.

In addition, the horizontal and vertical gaps are set to the specified values. Horizontal gaps are placed at the left and right edges, and between each of the columns. Vertical gaps are placed at the top and bottom edges, and between each of the rows.

One, but not both, of rows and cols can be zero, which means that any number of objects can be placed in a row or in a column.

All GridLayout constructors defer to this one.

Parameters:
rows - the rows, with the value zero meaning any number of rows
cols - the columns, with the value zero meaning any number of columns
hgap - the horizontal gap
vgap - the vertical gap
Throws:
IllegalArgumentException - if the value of both rows and cols is set to zero
Method Detail

getRows

public int getRows()
Gets the number of rows in this layout.

Returns:
the number of rows in this layout

setRows

public void setRows(int rows)
Sets the number of rows in this layout to the specified value.

Parameters:
rows - the number of rows in this layout
Throws:
IllegalArgumentException - if the value of both rows and cols is set to zero

getColumns

public int getColumns()
Gets the number of columns in this layout.

Returns:
the number of columns in this layout

setColumns

public void setColumns(int cols)
Sets the number of columns in this layout to the specified value. Setting the number of columns has no affect on the layout if the number of rows specified by a constructor or by the setRows method is non-zero. In that case, the number of columns displayed in the layout is determined by the total number of components and the number of rows specified.

Parameters:
cols - the number of columns in this layout
Throws:
IllegalArgumentException - if the value of both rows and cols is set to zero

getHgap

public int getHgap()
Gets the horizontal gap between components.

Returns:
the horizontal gap between components

setHgap

public void setHgap(int hgap)
Sets the horizontal gap between components to the specified value.

Parameters:
hgap - the horizontal gap between components

getVgap

public int getVgap()
Gets the vertical gap between components.

Returns:
the vertical gap between components

setVgap

public void setVgap(int vgap)
Sets the vertical gap between components to the specified value.

Parameters:
vgap - the vertical gap between components

addLayoutComponent

public void addLayoutComponent(String name,
                               Component comp)
If the layout manager uses a per-component string, adds the component comp to the layout, associating it with the string specified by name.

Specified by:
addLayoutComponent in interface LayoutManager
Parameters:
name - the string to be associated with the component
comp - the component to be added

addLayoutComponent

public void addLayoutComponent(Component comp,
                               Object constraints)
Adds the specified component to the layout, using the specified constraint object.

Specified by:
addLayoutComponent in interface LayoutManager2
Parameters:
comp - the component to be added
constraints - where/how the component is added to the layout.

removeLayoutComponent

public void removeLayoutComponent(Component comp)
Removes the specified component from the layout.

Specified by:
removeLayoutComponent in interface LayoutManager
Parameters:
comp - the component to be removed

preferredLayoutSize

public Dimension preferredLayoutSize(Container parent)
Calculates the preferred size dimensions for the specified container, given the components it contains.

Specified by:
preferredLayoutSize in interface LayoutManager
Parameters:
parent - the container to be laid out
See Also:
minimumLayoutSize(java.awt.Container)

minimumLayoutSize

public Dimension minimumLayoutSize(Container parent)
Calculates the minimum size dimensions for the specified container, given the components it contains.

Specified by:
minimumLayoutSize in interface LayoutManager
Parameters:
parent - the component to be laid out
See Also:
preferredLayoutSize(java.awt.Container)

maximumLayoutSize

public Dimension maximumLayoutSize(Container parent)
Calculates the maximum size dimensions for the specified container, given the components it contains.

Specified by:
maximumLayoutSize in interface LayoutManager2
See Also:
Component.getMaximumSize(), LayoutManager

layoutContainer

public void layoutContainer(Container parent)
Lays out the specified container.

Specified by:
layoutContainer in interface LayoutManager
Parameters:
parent - the container to be laid out

invalidateLayout

public void invalidateLayout(Container parent)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.

Specified by:
invalidateLayout in interface LayoutManager2

getLayoutAlignmentX

public float getLayoutAlignmentX(Container parent)
Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

Specified by:
getLayoutAlignmentX in interface LayoutManager2

getLayoutAlignmentY

public float getLayoutAlignmentY(Container parent)
Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.

Specified by:
getLayoutAlignmentY in interface LayoutManager2

JComponentPack 1.5.0

Send your Feedback
JComponentPack 1.5.0
Copyright © 2001-2007 Extreme Component, Inc. All rights reserved.