src/share/classes/java/awt/GridBagLayout.java

Print this page




 103  * <code>GridBagConstraints.BOTH</code>
 104  * (make the component fill its display area entirely).
 105  * <dt>{@link GridBagConstraints#ipadx},
 106  * {@link GridBagConstraints#ipady}
 107  * <dd>Specifies the component's internal padding within the layout,
 108  * how much to add to the minimum size of the component.
 109  * The width of the component will be at least its minimum width
 110  * plus <code>ipadx</code> pixels. Similarly, the height of
 111  * the component will be at least the minimum height plus
 112  * <code>ipady</code> pixels.
 113  * <dt>{@link GridBagConstraints#insets}
 114  * <dd>Specifies the component's external padding, the minimum
 115  * amount of space between the component and the edges of its display area.
 116  * <dt>{@link GridBagConstraints#anchor}
 117  * <dd>Specifies where the component should be positioned in its display area.
 118  * There are three kinds of possible values: absolute, orientation-relative,
 119  * and baseline-relative
 120  * Orientation relative values are interpreted relative to the container's
 121  * <code>ComponentOrientation</code> property while absolute values
 122  * are not.  Baseline relative values are calculated relative to the
 123  * baseline.  Valid values are:</dd>
 124  * <p>
 125  * <center><table BORDER=0 COLS=3 WIDTH=800
 126  *        SUMMARY="absolute, relative and baseline values as described above">
 127  * <tr>
 128  * <th><P ALIGN="LEFT">Absolute Values</th>
 129  * <th><P ALIGN="LEFT">Orientation Relative Values</th>
 130  * <th><P ALIGN="LEFT">Baseline Relative Values</th>
 131  * </tr>
 132  * <tr>
 133  * <td>

 134  * <li><code>GridBagConstraints.NORTH</code></li>
 135  * <li><code>GridBagConstraints.SOUTH</code></li>
 136  * <li><code>GridBagConstraints.WEST</code></li>
 137  * <li><code>GridBagConstraints.EAST</code></li>
 138  * <li><code>GridBagConstraints.NORTHWEST</code></li>
 139  * <li><code>GridBagConstraints.NORTHEAST</code></li>
 140  * <li><code>GridBagConstraints.SOUTHWEST</code></li>
 141  * <li><code>GridBagConstraints.SOUTHEAST</code></li>
 142  * <li><code>GridBagConstraints.CENTER</code> (the default)</li>

 143  * </td>
 144  * <td>

 145  * <li><code>GridBagConstraints.PAGE_START</code></li>
 146  * <li><code>GridBagConstraints.PAGE_END</code></li>
 147  * <li><code>GridBagConstraints.LINE_START</code></li>
 148  * <li><code>GridBagConstraints.LINE_END</code></li>
 149  * <li><code>GridBagConstraints.FIRST_LINE_START</code></li>
 150  * <li><code>GridBagConstraints.FIRST_LINE_END</code></li>
 151  * <li><code>GridBagConstraints.LAST_LINE_START</code></li>
 152  * <li><code>GridBagConstraints.LAST_LINE_END</code></li>

 153  * </td>
 154  * <td>

 155  * <li><code>GridBagConstraints.BASELINE</code></li>
 156  * <li><code>GridBagConstraints.BASELINE_LEADING</code></li>
 157  * <li><code>GridBagConstraints.BASELINE_TRAILING</code></li>
 158  * <li><code>GridBagConstraints.ABOVE_BASELINE</code></li>
 159  * <li><code>GridBagConstraints.ABOVE_BASELINE_LEADING</code></li>
 160  * <li><code>GridBagConstraints.ABOVE_BASELINE_TRAILING</code></li>
 161  * <li><code>GridBagConstraints.BELOW_BASELINE</code></li>
 162  * <li><code>GridBagConstraints.BELOW_BASELINE_LEADING</code></li>
 163  * <li><code>GridBagConstraints.BELOW_BASELINE_TRAILING</code></li>

 164  * </td>
 165  * </tr>
 166  * </table></center><p>
 167  * <dt>{@link GridBagConstraints#weightx},
 168  * {@link GridBagConstraints#weighty}
 169  * <dd>Used to determine how to distribute space, which is
 170  * important for specifying resizing behavior.
 171  * Unless you specify a weight for at least one component
 172  * in a row (<code>weightx</code>) and column (<code>weighty</code>),
 173  * all the components clump together in the center of their container.
 174  * This is because when the weight is zero (the default),
 175  * the <code>GridBagLayout</code> object puts any extra space
 176  * between its grid of cells and the edges of the container.
 177  * </dl>
 178  * <p>
 179  * Each row may have a baseline; the baseline is determined by the
 180  * components in that row that have a valid baseline and are aligned
 181  * along the baseline (the component's anchor value is one of {@code
 182  * BASELINE}, {@code BASELINE_LEADING} or {@code BASELINE_TRAILING}).
 183  * If none of the components in the row has a valid baseline, the row
 184  * does not have a baseline.
 185  * <p>
 186  * If a component spans rows it is aligned either to the baseline of


 229  * <li>Resizable components positioned on the baseline with a
 230  * baseline-resize behavior of <code>OTHER</code> are only resized if
 231  * the baseline at the resized size fits within the display area.  If
 232  * the baseline is such that it does not fit within the display area
 233  * the component is not resized.
 234  * <li>Components positioned on the baseline that do not have a
 235  * baseline-resize behavior of <code>OTHER</code>
 236  * can only grow as tall as {@code display height - baseline + baseline of component}.
 237  * </ul>
 238  * If you position a component along the baseline, but the
 239  * component does not have a valid baseline, it will be vertically centered
 240  * in its space.  Similarly if you have positioned a component relative
 241  * to the baseline and none of the components in the row have a valid
 242  * baseline the component is vertically centered.
 243  * <p>
 244  * The following figures show ten components (all buttons)
 245  * managed by a grid bag layout.  Figure 2 shows the layout for a horizontal,
 246  * left-to-right container and Figure 3 shows the layout for a horizontal,
 247  * right-to-left container.
 248  * <p>
 249  * <center><table COLS=2 WIDTH=600 summary="layout">
 250  * <tr ALIGN=CENTER>
 251  * <td>
 252  * <img src="doc-files/GridBagLayout-1.gif" alt="The preceeding text describes this graphic (Figure 1)." ALIGN=center HSPACE=10 VSPACE=7>
 253  * </td>
 254  * <td>
 255  * <img src="doc-files/GridBagLayout-2.gif" alt="The preceeding text describes this graphic (Figure 2)." ALIGN=center HSPACE=10 VSPACE=7>
 256  * </td>
 257  * <tr ALIGN=CENTER>
 258  * <td>Figure 2: Horizontal, Left-to-Right</td>
 259  * <td>Figure 3: Horizontal, Right-to-Left</td>
 260  * </tr>
 261  * </table></center>
 262  * <p>
 263  * Each of the ten components has the <code>fill</code> field
 264  * of its associated <code>GridBagConstraints</code> object
 265  * set to <code>GridBagConstraints.BOTH</code>.
 266  * In addition, the components have the following non-default constraints:
 267  * <p>
 268  * <ul>
 269  * <li>Button1, Button2, Button3: <code>weightx&nbsp;=&nbsp;1.0</code>


 332  *         makebutton("Button10", gridbag, c);
 333  *
 334  *         setSize(300, 100);
 335  *     }
 336  *
 337  *     public static void main(String args[]) {
 338  *         Frame f = new Frame("GridBag Layout Example");
 339  *         GridBagEx1 ex1 = new GridBagEx1();
 340  *
 341  *         ex1.init();
 342  *
 343  *         f.add("Center", ex1);
 344  *         f.pack();
 345  *         f.setSize(f.getPreferredSize());
 346  *         f.show();
 347  *     }
 348  * }
 349  * </pre></blockquote><hr>
 350  * <p>
 351  * @author Doug Stein
 352  * @author Bill Spitzak (orignial NeWS & OLIT implementation)
 353  * @see       java.awt.GridBagConstraints
 354  * @see       java.awt.GridBagLayoutInfo
 355  * @see       java.awt.ComponentOrientation
 356  * @since JDK1.0
 357  */
 358 public class GridBagLayout implements LayoutManager2,
 359 java.io.Serializable {
 360 
 361     static final int EMPIRICMULTIPLIER = 2;
 362     /**
 363      * This field is no longer used to reserve arrays and keeped for backward
 364      * compatibility. Previously, this was
 365      * the maximum number of grid positions (both horizontal and
 366      * vertical) that could be laid out by the grid bag layout.
 367      * Current implementation doesn't impose any limits
 368      * on the size of a grid.
 369      */
 370     protected static final int MAXGRIDSIZE = 512;
 371 
 372     /**




 103  * <code>GridBagConstraints.BOTH</code>
 104  * (make the component fill its display area entirely).
 105  * <dt>{@link GridBagConstraints#ipadx},
 106  * {@link GridBagConstraints#ipady}
 107  * <dd>Specifies the component's internal padding within the layout,
 108  * how much to add to the minimum size of the component.
 109  * The width of the component will be at least its minimum width
 110  * plus <code>ipadx</code> pixels. Similarly, the height of
 111  * the component will be at least the minimum height plus
 112  * <code>ipady</code> pixels.
 113  * <dt>{@link GridBagConstraints#insets}
 114  * <dd>Specifies the component's external padding, the minimum
 115  * amount of space between the component and the edges of its display area.
 116  * <dt>{@link GridBagConstraints#anchor}
 117  * <dd>Specifies where the component should be positioned in its display area.
 118  * There are three kinds of possible values: absolute, orientation-relative,
 119  * and baseline-relative
 120  * Orientation relative values are interpreted relative to the container's
 121  * <code>ComponentOrientation</code> property while absolute values
 122  * are not.  Baseline relative values are calculated relative to the
 123  * baseline.  Valid values are:
 124  * <p>
 125  * <center><table BORDER=0 WIDTH=800
 126  *        SUMMARY="absolute, relative and baseline values as described above">
 127  * <tr>
 128  * <th><P ALIGN="LEFT">Absolute Values</th>
 129  * <th><P ALIGN="LEFT">Orientation Relative Values</th>
 130  * <th><P ALIGN="LEFT">Baseline Relative Values</th>
 131  * </tr>
 132  * <tr>
 133  * <td>
 134  * <ul style="list-style-type:none">
 135  * <li><code>GridBagConstraints.NORTH</code></li>
 136  * <li><code>GridBagConstraints.SOUTH</code></li>
 137  * <li><code>GridBagConstraints.WEST</code></li>
 138  * <li><code>GridBagConstraints.EAST</code></li>
 139  * <li><code>GridBagConstraints.NORTHWEST</code></li>
 140  * <li><code>GridBagConstraints.NORTHEAST</code></li>
 141  * <li><code>GridBagConstraints.SOUTHWEST</code></li>
 142  * <li><code>GridBagConstraints.SOUTHEAST</code></li>
 143  * <li><code>GridBagConstraints.CENTER</code> (the default)</li>
 144  * </ul>
 145  * </td>
 146  * <td>
 147  * <ul style="list-style-type:none">
 148  * <li><code>GridBagConstraints.PAGE_START</code></li>
 149  * <li><code>GridBagConstraints.PAGE_END</code></li>
 150  * <li><code>GridBagConstraints.LINE_START</code></li>
 151  * <li><code>GridBagConstraints.LINE_END</code></li>
 152  * <li><code>GridBagConstraints.FIRST_LINE_START</code></li>
 153  * <li><code>GridBagConstraints.FIRST_LINE_END</code></li>
 154  * <li><code>GridBagConstraints.LAST_LINE_START</code></li>
 155  * <li><code>GridBagConstraints.LAST_LINE_END</code></li>
 156  * </ul>
 157  * </td>
 158  * <td>
 159  * <ul style="list-style-type:none">
 160  * <li><code>GridBagConstraints.BASELINE</code></li>
 161  * <li><code>GridBagConstraints.BASELINE_LEADING</code></li>
 162  * <li><code>GridBagConstraints.BASELINE_TRAILING</code></li>
 163  * <li><code>GridBagConstraints.ABOVE_BASELINE</code></li>
 164  * <li><code>GridBagConstraints.ABOVE_BASELINE_LEADING</code></li>
 165  * <li><code>GridBagConstraints.ABOVE_BASELINE_TRAILING</code></li>
 166  * <li><code>GridBagConstraints.BELOW_BASELINE</code></li>
 167  * <li><code>GridBagConstraints.BELOW_BASELINE_LEADING</code></li>
 168  * <li><code>GridBagConstraints.BELOW_BASELINE_TRAILING</code></li>
 169  * </ul>
 170  * </td>
 171  * </tr>
 172  * </table></center>
 173  * <dt>{@link GridBagConstraints#weightx},
 174  * {@link GridBagConstraints#weighty}
 175  * <dd>Used to determine how to distribute space, which is
 176  * important for specifying resizing behavior.
 177  * Unless you specify a weight for at least one component
 178  * in a row (<code>weightx</code>) and column (<code>weighty</code>),
 179  * all the components clump together in the center of their container.
 180  * This is because when the weight is zero (the default),
 181  * the <code>GridBagLayout</code> object puts any extra space
 182  * between its grid of cells and the edges of the container.
 183  * </dl>
 184  * <p>
 185  * Each row may have a baseline; the baseline is determined by the
 186  * components in that row that have a valid baseline and are aligned
 187  * along the baseline (the component's anchor value is one of {@code
 188  * BASELINE}, {@code BASELINE_LEADING} or {@code BASELINE_TRAILING}).
 189  * If none of the components in the row has a valid baseline, the row
 190  * does not have a baseline.
 191  * <p>
 192  * If a component spans rows it is aligned either to the baseline of


 235  * <li>Resizable components positioned on the baseline with a
 236  * baseline-resize behavior of <code>OTHER</code> are only resized if
 237  * the baseline at the resized size fits within the display area.  If
 238  * the baseline is such that it does not fit within the display area
 239  * the component is not resized.
 240  * <li>Components positioned on the baseline that do not have a
 241  * baseline-resize behavior of <code>OTHER</code>
 242  * can only grow as tall as {@code display height - baseline + baseline of component}.
 243  * </ul>
 244  * If you position a component along the baseline, but the
 245  * component does not have a valid baseline, it will be vertically centered
 246  * in its space.  Similarly if you have positioned a component relative
 247  * to the baseline and none of the components in the row have a valid
 248  * baseline the component is vertically centered.
 249  * <p>
 250  * The following figures show ten components (all buttons)
 251  * managed by a grid bag layout.  Figure 2 shows the layout for a horizontal,
 252  * left-to-right container and Figure 3 shows the layout for a horizontal,
 253  * right-to-left container.
 254  * <p>
 255  * <center><table WIDTH=600 summary="layout">
 256  * <tr ALIGN=CENTER>
 257  * <td>
 258  * <img src="doc-files/GridBagLayout-1.gif" alt="The preceeding text describes this graphic (Figure 1)." ALIGN=center HSPACE=10 VSPACE=7>
 259  * </td>
 260  * <td>
 261  * <img src="doc-files/GridBagLayout-2.gif" alt="The preceeding text describes this graphic (Figure 2)." ALIGN=center HSPACE=10 VSPACE=7>
 262  * </td>
 263  * <tr ALIGN=CENTER>
 264  * <td>Figure 2: Horizontal, Left-to-Right</td>
 265  * <td>Figure 3: Horizontal, Right-to-Left</td>
 266  * </tr>
 267  * </table></center>
 268  * <p>
 269  * Each of the ten components has the <code>fill</code> field
 270  * of its associated <code>GridBagConstraints</code> object
 271  * set to <code>GridBagConstraints.BOTH</code>.
 272  * In addition, the components have the following non-default constraints:
 273  * <p>
 274  * <ul>
 275  * <li>Button1, Button2, Button3: <code>weightx&nbsp;=&nbsp;1.0</code>


 338  *         makebutton("Button10", gridbag, c);
 339  *
 340  *         setSize(300, 100);
 341  *     }
 342  *
 343  *     public static void main(String args[]) {
 344  *         Frame f = new Frame("GridBag Layout Example");
 345  *         GridBagEx1 ex1 = new GridBagEx1();
 346  *
 347  *         ex1.init();
 348  *
 349  *         f.add("Center", ex1);
 350  *         f.pack();
 351  *         f.setSize(f.getPreferredSize());
 352  *         f.show();
 353  *     }
 354  * }
 355  * </pre></blockquote><hr>
 356  * <p>
 357  * @author Doug Stein
 358  * @author Bill Spitzak (orignial NeWS &amp; OLIT implementation)
 359  * @see       java.awt.GridBagConstraints
 360  * @see       java.awt.GridBagLayoutInfo
 361  * @see       java.awt.ComponentOrientation
 362  * @since JDK1.0
 363  */
 364 public class GridBagLayout implements LayoutManager2,
 365 java.io.Serializable {
 366 
 367     static final int EMPIRICMULTIPLIER = 2;
 368     /**
 369      * This field is no longer used to reserve arrays and keeped for backward
 370      * compatibility. Previously, this was
 371      * the maximum number of grid positions (both horizontal and
 372      * vertical) that could be laid out by the grid bag layout.
 373      * Current implementation doesn't impose any limits
 374      * on the size of a grid.
 375      */
 376     protected static final int MAXGRIDSIZE = 512;
 377 
 378     /**