Setting the Stretchyness of Columns and Rows in a GridBagLayout Using Component Weights
See Setting the Stretchyness of Rows and Columns in a GridBagLayout Using Layout Weights for an explanation of
stretchyness and weights. This example demonstrates how to set the
weight of a row or column by assigning the weight on a
component.
See Creating a GridBagLayout for an example on how to
use a gridbag layout with gridbag constraints.
GridBagLayout gbl = new GridBagLayout();
container.setLayout(gbl);
// Place a component at (0,1) with a column weight 1 and
// a row weight of 2
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.weightx = 1;
gbc.weighty = 2;
gbl.setConstraints(component, gbc);
container.add(component);
Post a comment