Among the many ways that you can condition
the instance of GridBagConstraints
, two deserve special mention.
First, you arrange for particular components to expand by setting the
weightx
or weighty
instance variables, or both, of the
gridbag constraint:
gbc.weightx = 1.0; <-- Spread out horizontally gbc.weighty = 1.0; <-- Spread out vertically
Second, you arrange for the expandable component to fill the available space by
setting the fill
instance variable to the value of the
BOTH
class variable:
gbc.fill = GridBagConstraints.BOTH; <-- Fill space
If you want to fill one way, but not the other, you use the
HORIZONTAL
or VERTICAL
class-variable values, rather
than the BOTH
class variable value.