src/java.desktop/share/classes/java/awt/GridBagLayout.java
changeset 58325 d32a3b1ca84a
parent 52248 2e330da7cbf4
equal deleted inserted replaced
58324:0aba35254e00 58325:d32a3b1ca84a
     1 /*
     1 /*
     2  * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   114  * <dd>Specifies the component's external padding, the minimum
   114  * <dd>Specifies the component's external padding, the minimum
   115  * amount of space between the component and the edges of its display area.
   115  * amount of space between the component and the edges of its display area.
   116  * <dt>{@link GridBagConstraints#anchor}
   116  * <dt>{@link GridBagConstraints#anchor}
   117  * <dd>Specifies where the component should be positioned in its display area.
   117  * <dd>Specifies where the component should be positioned in its display area.
   118  * There are three kinds of possible values: absolute, orientation-relative,
   118  * There are three kinds of possible values: absolute, orientation-relative,
   119  * and baseline-relative
   119  * and baseline-relative.
   120  * Orientation relative values are interpreted relative to the container's
   120  * Orientation relative values are interpreted relative to the container's
   121  * {@code ComponentOrientation} property while absolute values
   121  * {@code ComponentOrientation} property while absolute values
   122  * are not.  Baseline relative values are calculated relative to the
   122  * are not.  Baseline relative values are calculated relative to the
   123  * baseline.  Valid values are:
   123  * baseline.  Valid values are:
   124  *
   124  *
   125  * <table class="striped" style="margin: 0px auto">
   125  * <ul>
   126  * <caption>Absolute, relative and baseline values as described above</caption>
   126  *   <li>Absolute Values:
   127  * <thead>
   127  *     <ul>
   128  * <tr>
   128  *       <li>{@code GridBagConstraints.NORTH}
   129  * <th><p style="text-align:center">Absolute Values</th>
   129  *       <li>{@code GridBagConstraints.SOUTH}
   130  * <th><p style="text-align:center">Orientation Relative Values</th>
   130  *       <li>{@code GridBagConstraints.WEST}
   131  * <th><p style="text-align:center">Baseline Relative Values</th>
   131  *       <li>{@code GridBagConstraints.EAST}
   132  * </tr>
   132  *       <li>{@code GridBagConstraints.NORTHWEST}
   133  * </thead>
   133  *       <li>{@code GridBagConstraints.NORTHEAST}
   134  * <tbody>
   134  *       <li>{@code GridBagConstraints.SOUTHWEST}
   135  * <tr>
   135  *       <li>{@code GridBagConstraints.SOUTHEAST}
   136  * <td>
   136  *       <li>{@code GridBagConstraints.CENTER} (the default)
   137  * <ul style="list-style-type:none">
   137  *     </ul>
   138  * <li>{@code GridBagConstraints.NORTH}</li>
   138  *   <li>Orientation Relative Values:
   139  * <li>{@code GridBagConstraints.SOUTH}</li>
   139  *     <ul >
   140  * <li>{@code GridBagConstraints.WEST}</li>
   140  *       <li>{@code GridBagConstraints.PAGE_START}
   141  * <li>{@code GridBagConstraints.EAST}</li>
   141  *       <li>{@code GridBagConstraints.PAGE_END}
   142  * <li>{@code GridBagConstraints.NORTHWEST}</li>
   142  *       <li>{@code GridBagConstraints.LINE_START}
   143  * <li>{@code GridBagConstraints.NORTHEAST}</li>
   143  *       <li>{@code GridBagConstraints.LINE_END}
   144  * <li>{@code GridBagConstraints.SOUTHWEST}</li>
   144  *       <li>{@code GridBagConstraints.FIRST_LINE_START}
   145  * <li>{@code GridBagConstraints.SOUTHEAST}</li>
   145  *       <li>{@code GridBagConstraints.FIRST_LINE_END}
   146  * <li>{@code GridBagConstraints.CENTER} (the default)</li>
   146  *       <li>{@code GridBagConstraints.LAST_LINE_START}
       
   147  *       <li>{@code GridBagConstraints.LAST_LINE_END}
       
   148  *     </ul>
       
   149  *   <li>Baseline Relative Values:
       
   150  *     <ul>
       
   151  *       <li>{@code GridBagConstraints.BASELINE}
       
   152  *       <li>{@code GridBagConstraints.BASELINE_LEADING}
       
   153  *       <li>{@code GridBagConstraints.BASELINE_TRAILING}
       
   154  *       <li>{@code GridBagConstraints.ABOVE_BASELINE}
       
   155  *       <li>{@code GridBagConstraints.ABOVE_BASELINE_LEADING}
       
   156  *       <li>{@code GridBagConstraints.ABOVE_BASELINE_TRAILING}
       
   157  *       <li>{@code GridBagConstraints.BELOW_BASELINE}
       
   158  *       <li>{@code GridBagConstraints.BELOW_BASELINE_LEADING}
       
   159  *       <li>{@code GridBagConstraints.BELOW_BASELINE_TRAILING}
       
   160  *     </ul>
   147  * </ul>
   161  * </ul>
   148  * </td>
       
   149  * <td>
       
   150  * <ul style="list-style-type:none">
       
   151  * <li>{@code GridBagConstraints.PAGE_START}</li>
       
   152  * <li>{@code GridBagConstraints.PAGE_END}</li>
       
   153  * <li>{@code GridBagConstraints.LINE_START}</li>
       
   154  * <li>{@code GridBagConstraints.LINE_END}</li>
       
   155  * <li>{@code GridBagConstraints.FIRST_LINE_START}</li>
       
   156  * <li>{@code GridBagConstraints.FIRST_LINE_END}</li>
       
   157  * <li>{@code GridBagConstraints.LAST_LINE_START}</li>
       
   158  * <li>{@code GridBagConstraints.LAST_LINE_END}</li>
       
   159  * </ul>
       
   160  * </td>
       
   161  * <td>
       
   162  * <ul style="list-style-type:none">
       
   163  * <li>{@code GridBagConstraints.BASELINE}</li>
       
   164  * <li>{@code GridBagConstraints.BASELINE_LEADING}</li>
       
   165  * <li>{@code GridBagConstraints.BASELINE_TRAILING}</li>
       
   166  * <li>{@code GridBagConstraints.ABOVE_BASELINE}</li>
       
   167  * <li>{@code GridBagConstraints.ABOVE_BASELINE_LEADING}</li>
       
   168  * <li>{@code GridBagConstraints.ABOVE_BASELINE_TRAILING}</li>
       
   169  * <li>{@code GridBagConstraints.BELOW_BASELINE}</li>
       
   170  * <li>{@code GridBagConstraints.BELOW_BASELINE_LEADING}</li>
       
   171  * <li>{@code GridBagConstraints.BELOW_BASELINE_TRAILING}</li>
       
   172  * </ul>
       
   173  * </td>
       
   174  * </tr>
       
   175  * </tbody>
       
   176  * </table>
       
   177  * <dt>{@link GridBagConstraints#weightx},
   162  * <dt>{@link GridBagConstraints#weightx},
   178  * {@link GridBagConstraints#weighty}
   163  * {@link GridBagConstraints#weighty}
   179  * <dd>Used to determine how to distribute space, which is
   164  * <dd>Used to determine how to distribute space, which is
   180  * important for specifying resizing behavior.
   165  * important for specifying resizing behavior.
   181  * Unless you specify a weight for at least one component
   166  * Unless you specify a weight for at least one component
   199  * is {@code CONSTANT_DESCENT}).  The row that the component is
   184  * is {@code CONSTANT_DESCENT}).  The row that the component is
   200  * aligned to is called the <em>prevailing row</em>.
   185  * aligned to is called the <em>prevailing row</em>.
   201  * <p>
   186  * <p>
   202  * The following figure shows a baseline layout and includes a
   187  * The following figure shows a baseline layout and includes a
   203  * component that spans rows:
   188  * component that spans rows:
   204  * <table class="borderless" style="margin: 0px auto">
   189  * <p style="text-align: center">
   205  * <caption>Baseline Layout</caption>
   190  *   <img src="doc-files/GridBagLayout-baseline.png"
   206  * <tr style="text-align:center">
   191  *   alt="The following text describes this graphic (Figure 1).">
   207  * <td>
   192  * </p>
   208  * <img src="doc-files/GridBagLayout-baseline.png"
       
   209  *  alt="The following text describes this graphic (Figure 1)." style="float:center">
       
   210  * </td>
       
   211  * </table>
       
   212  * This layout consists of three components:
   193  * This layout consists of three components:
   213  * <ul><li>A panel that starts in row 0 and ends in row 1.  The panel
   194  * <ul><li>A panel that starts in row 0 and ends in row 1.  The panel
   214  *   has a baseline-resize behavior of {@code CONSTANT_DESCENT} and has
   195  *   has a baseline-resize behavior of {@code CONSTANT_DESCENT} and has
   215  *   an anchor of {@code BASELINE}.  As the baseline-resize behavior
   196  *   an anchor of {@code BASELINE}.  As the baseline-resize behavior
   216  *   is {@code CONSTANT_DESCENT} the prevailing row for the panel is
   197  *   is {@code CONSTANT_DESCENT} the prevailing row for the panel is
   255  * The following figures show ten components (all buttons)
   236  * The following figures show ten components (all buttons)
   256  * managed by a grid bag layout.  Figure 2 shows the layout for a horizontal,
   237  * managed by a grid bag layout.  Figure 2 shows the layout for a horizontal,
   257  * left-to-right container and Figure 3 shows the layout for a horizontal,
   238  * left-to-right container and Figure 3 shows the layout for a horizontal,
   258  * right-to-left container.
   239  * right-to-left container.
   259  *
   240  *
   260  * <table class="borderless" style="margin: 0px auto">
   241  * <div style="margin:0 auto;width:680px;text-align:center;font-weight:bold">
   261  * <caption style="width:600;display:none">Figures</caption>
   242  *   <div style="float:left">
   262  * <tr style="text-align:center">
   243  *     <p><img src="doc-files/GridBagLayout-1.gif"
   263  * <td>
   244  *        alt="The preceding text describes this graphic (Figure 2)."
   264  * <img src="doc-files/GridBagLayout-1.gif" alt="The preceding text describes this graphic (Figure 1)." style="float:center; margin: 7px 10px;">
   245  *        style="margin: 7px 10px;">
   265  * </td>
   246  *     <p>Figure 2: Horizontal, Left-to-Right
   266  * <td>
   247  *   </div>
   267  * <img src="doc-files/GridBagLayout-2.gif" alt="The preceding text describes this graphic (Figure 2)." style="float:center; margin: 7px 10px;">
   248  *   <div style="float:right">
   268  * </td>
   249  *     <p><img src="doc-files/GridBagLayout-2.gif"
   269  * <tr style="text-align:center">
   250  *        alt="The preceding text describes this graphic (Figure 3)."
   270  * <td>Figure 2: Horizontal, Left-to-Right</td>
   251  *        style="margin: 7px 10px;">
   271  * <td>Figure 3: Horizontal, Right-to-Left</td>
   252  *     <p>Figure 3: Horizontal, Right-to-Left
   272  * </tr>
   253  *   </div>
   273  * </table>
   254  *   <br style="clear:both;">
       
   255  * </div>
   274  * <p>
   256  * <p>
   275  * Each of the ten components has the {@code fill} field
   257  * Each of the ten components has the {@code fill} field
   276  * of its associated {@code GridBagConstraints} object
   258  * of its associated {@code GridBagConstraints} object
   277  * set to {@code GridBagConstraints.BOTH}.
   259  * set to {@code GridBagConstraints.BOTH}.
   278  * In addition, the components have the following non-default constraints:
   260  * In addition, the components have the following non-default constraints: