Using the REMAINDER Value for a Width : GridBagConstraints « Swing « Java Tutorial






Using the REMAINDER Value for a Width
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

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

public class GridBagLayoutRemainder {

  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();
    pane.add(new JButton("First row, first column"), gbc);
    pane.add(new JButton("First row, second column"), gbc);
    pane.add(new JButton("First row, third column"), gbc);
    gbc.gridx = 0;
    pane.add(new JButton("Second row"), gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    pane.add(new JButton("Third row, gridwidth set to REMAINDER"), gbc);
    f.setSize(600, 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