Core Java - [AWT GridBag Layout Manager]

♠ Posted by Unknown in at 21:48

GridBagLayout


The GridBagLayout manager is the most flexible and most complex. The components can vary in size, however, and can be added in any order in GridBagLayout.

The Constructor GridBagLayout() is used to create a new GridBagLayout. 

In the GridLayout, the grid size (the number of rows and columns) is specified in the constructor. The size is unspecified, however, in the GridBagLayout. How a GridBagLayout places a set of components depends on each component's GridBagConstraints and minimum size, as well as the preferred size of the component's container.

gridx and gridy :
Specifies the cell at the upper left of the component's display area, where the upper left most cell has address gridx=0 and gridy=0.

numrows and numcols:
Specifies the number of cells ina row or column in the component's display area. the default value is 1.

weightx and weighty:
Specifies the extra space to allocate horizontally and vertically for the component in a row and a column, all the component clump together in the center of their container.

fill:
Specifies how the component should be resized if the component's viewing area is larger than its current size.

Valid Values are,
1. GridBagConstraints.NONE
2. GridBagConstraints.HORIZONTAL
3.GridBagConstraints.VERTICAL
4. GridBagConstraints.BOTH

anchor:
GridBagConstraint.CENTER (the default)
GridBagConstraint.NORTH
GridBagConstraint.NORTHEAST
GridBagConstraint.EAST
GridBagConstraint.SOUTHEAST
GridBagConstraint.SOUTH
GridBagConstraint.SOUTHWEST
GridBagConstraint.WEST
GridBagConstraint.NORTHWEST

The fill and anchor parameters deal with how to fill and place the component when the viewing area is larger than the requested area.


0 comments:

Post a Comment