![]() |
The Java Developers Almanac 1.4 |
|
e628. Setting the Stretchyness of a Component Within the Cell of a GridBagLayout Using FillBy default, when the cell is larger than the preferred size of a component, the component is centered within the cell. You can stretch a component horizontally or vertically, or in both directions within the cell by setting its fill constraint.See e622 Creating a GridBagLayout for an example on how to use a gridbag layout with gridbag constraints. GridBagLayout gbl = new GridBagLayout();
container.setLayout(gbl);
GridBagConstraints gbc = new GridBagConstraints();
// Make the component on stretchable
gbc.fill = GridBagConstraints.NONE;
// Make the component only stretch horizontally
gbc.fill = GridBagConstraints.HORIZONTAL;
// Make the component only stretch vertically
gbc.fill = GridBagConstraints.VERTICAL;
// Make the component stretch in both directions
gbc.fill = GridBagConstraints.BOTH;
gbl.setConstraints(component, gbc);
container.add(component);
e623. Setting the Location of a Component in a GridBagLayout e624. Getting the Number of Rows and Columns of Cells in a GridBagLayout e625. Making a GridBagLayout Fill the Container e626. Setting the Stretchyness of Rows and Columns in a GridBagLayout Using Layout Weights e627. Setting the Stretchyness of Columns and Rows in a GridBagLayout Using Component Weights e629. Setting the Location of a Component Within the Cell of a GridBagLayout Using Anchors e630. Setting the Space around a Component Within the Cell of the GridBagLayout Using Insets e631. Adjusting the Size of a Component in a GridBadLayout Using Internal Padding e632. Setting a Row or Column of a GridBadLayout to a Particular Size e633. Setting Gap Sizes in a GridBadLayout
© 2002 Addison-Wesley. |