Effects of the fill Constraint : GridBagConstraints « Swing « Java Tutorial






Effects of the fill Constraint
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

public class GridBagLayoutFill {

  public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = f.getContentPane();
    pane.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = GridBagConstraints.RELATIVE;
    pane.add(new JButton("This button's preferred width " + "is large because its text is long"),
        gbc);
    pane.add(new JButton("Small centered button"), gbc);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    pane.add(new JButton("Expands to fill column width"), gbc);
    f.setSize(400, 300);
    f.setVisible(true);
  }

}








14.95.GridBagConstraints
14.95.1.Using GridBagConstraintsUsing GridBagConstraints
14.95.2.Adding Components with a Relative X PositionAdding Components with a Relative X Position
14.95.3.Adding Components with a Relative Y PositionAdding Components with a Relative Y Position
14.95.4.Adding Components with Relative X and Y CoordinatesAdding Components with Relative X and Y Coordinates
14.95.5.Effects of the fill ConstraintEffects of the fill Constraint
14.95.6.Effects of the gridwidth ConstraintEffects of the gridwidth Constraint
14.95.7.Filling the Entire ColumnFilling the Entire Column
14.95.8.Using the REMAINDER Value for a WidthUsing the REMAINDER Value for a Width
14.95.9.Effects of the gridheight ConstraintEffects of the gridheight Constraint
14.95.10.A Simple Application That Uses GridBagConstraints.WESTA Simple Application That Uses GridBagConstraints.WEST
14.95.11.Use GridBagLayout to layout RadioButtonsUse GridBagLayout to layout RadioButtons
14.95.12.A GridBagLayout Example: weightx, weighty