import java.awt.*; /** * Extension of GridBagConstraints with a simplified constructor * * @author Nobo Komagata * @version 5/29/03 */ public class GridBagC extends GridBagConstraints { // to set a position relative (next) to the previous value public static final int RELATIVE = GridBagConstraints.RELATIVE; // to set a span that fills in the remaining positions public static final int REMAINDER = GridBagConstraints.REMAINDER; /** * Constructor for objects of class GridBagC * * @param x pos, y pos, x span, y span [0-indexed] * @return a new instance * * // Example * // Y\X 0 1 2 * // 0 00 10 20 * // 1 01+11 21 * setLayout(new GridBagLayout()); * add(new Label("00"), new GridBagC(0, 0, 1, 1)); * add(new Label("10"), new GridBagC(1, 0, 1, 1)); * add(new Label("20"), new GridBagC(2, 0, 1, 1)); * add(new Label("01+11"), new GridBagC(0, 1, 2, 1)); * add(new Label("21"), new GridBagC(2, 1, 1, 1)); */ public GridBagC(int gridx, int gridy, int gridwidth, int gridheight) { this.gridx = gridx; this.gridy = gridy; this.gridwidth = gridwidth; this.gridheight = gridheight; this.weightx = 1.0; this.weighty = 1.0; this.anchor = GridBagConstraints.CENTER; this.fill = GridBagConstraints.BOTH; this.insets = new Insets(0, 0, 0, 5); // can be reset by "setInsets" this.ipadx = 0; this.ipady = 0; } /** * Manually set insets (margins) * * @param all arguments of the Insets constructor * @return a new instance */ public GridBagC setInsets(int top, int left, int bottom, int right) { this.insets = new Insets(top, left, bottom, right); return this; } }