< prev index next >

src/java.desktop/share/classes/java/awt/GridLayout.java

Print this page


   1 /*
   2  * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  38  * import java.awt.*;
  39  * import java.applet.Applet;
  40  * public class ButtonGrid extends Applet {
  41  *     public void init() {
  42  *         setLayout(new GridLayout(3,2));
  43  *         add(new Button("1"));
  44  *         add(new Button("2"));
  45  *         add(new Button("3"));
  46  *         add(new Button("4"));
  47  *         add(new Button("5"));
  48  *         add(new Button("6"));
  49  *     }
  50  * }
  51  * </pre></blockquote><hr>
  52  * <p>
  53  * If the container's {@code ComponentOrientation} property is horizontal
  54  * and left-to-right, the above example produces the output shown in Figure 1.
  55  * If the container's {@code ComponentOrientation} property is horizontal
  56  * and right-to-left, the example produces the output shown in Figure 2.
  57  *
  58  * <table style="float:center" WIDTH=600 summary="layout">
  59  * <tr ALIGN=CENTER>
  60  * <td><img SRC="doc-files/GridLayout-1.gif"
  61  *      alt="Shows 6 buttons in rows of 2. Row 1 shows buttons 1 then 2.
  62  * Row 2 shows buttons 3 then 4. Row 3 shows buttons 5 then 6.">
  63  * </td>
  64  *
  65  * <td ALIGN=CENTER><img SRC="doc-files/GridLayout-2.gif"
  66  *                   alt="Shows 6 buttons in rows of 2. Row 1 shows buttons 2 then 1.
  67  * Row 2 shows buttons 4 then 3. Row 3 shows buttons 6 then 5.">
  68  * </td>
  69  * </tr>
  70  *
  71  * <tr ALIGN=CENTER>
  72  * <td>Figure 1: Horizontal, Left-to-Right</td>
  73  *
  74  * <td>Figure 2: Horizontal, Right-to-Left</td>
  75  * </tr>
  76  * </table>
  77  * <p>
  78  * When both the number of rows and the number of columns have
  79  * been set to non-zero values, either by a constructor or
  80  * by the {@code setRows} and {@code setColumns} methods, the number of
  81  * columns specified is ignored.  Instead, the number of
  82  * columns is determined from the specified number of rows
  83  * and the total number of components in the layout. So, for
  84  * example, if three rows and two columns have been specified
  85  * and nine components are added to the layout, they will
  86  * be displayed as three rows of three columns.  Specifying
  87  * the number of columns affects the layout only when the
  88  * number of rows is set to zero.
  89  *
  90  * @author  Arthur van Hoff
  91  * @since   1.0


   1 /*
   2  * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  38  * import java.awt.*;
  39  * import java.applet.Applet;
  40  * public class ButtonGrid extends Applet {
  41  *     public void init() {
  42  *         setLayout(new GridLayout(3,2));
  43  *         add(new Button("1"));
  44  *         add(new Button("2"));
  45  *         add(new Button("3"));
  46  *         add(new Button("4"));
  47  *         add(new Button("5"));
  48  *         add(new Button("6"));
  49  *     }
  50  * }
  51  * </pre></blockquote><hr>
  52  * <p>
  53  * If the container's {@code ComponentOrientation} property is horizontal
  54  * and left-to-right, the above example produces the output shown in Figure 1.
  55  * If the container's {@code ComponentOrientation} property is horizontal
  56  * and right-to-left, the example produces the output shown in Figure 2.
  57  *
  58  * <table style="float:center;width:600" summary="layout">
  59  * <tr style="text-align:center">
  60  * <td><img SRC="doc-files/GridLayout-1.gif"
  61  *      alt="Shows 6 buttons in rows of 2. Row 1 shows buttons 1 then 2.
  62  * Row 2 shows buttons 3 then 4. Row 3 shows buttons 5 then 6.">
  63  * </td>
  64  *
  65  * <td style="text-align:center"><img SRC="doc-files/GridLayout-2.gif"
  66  *              alt="Shows 6 buttons in rows of 2. Row 1 shows buttons 2 then 1.
  67  * Row 2 shows buttons 4 then 3. Row 3 shows buttons 6 then 5.">
  68  * </td>
  69  * </tr>
  70  *
  71  * <tr style="text-align:center">
  72  * <td>Figure 1: Horizontal, Left-to-Right</td>
  73  *
  74  * <td>Figure 2: Horizontal, Right-to-Left</td>
  75  * </tr>
  76  * </table>
  77  * <p>
  78  * When both the number of rows and the number of columns have
  79  * been set to non-zero values, either by a constructor or
  80  * by the {@code setRows} and {@code setColumns} methods, the number of
  81  * columns specified is ignored.  Instead, the number of
  82  * columns is determined from the specified number of rows
  83  * and the total number of components in the layout. So, for
  84  * example, if three rows and two columns have been specified
  85  * and nine components are added to the layout, they will
  86  * be displayed as three rows of three columns.  Specifying
  87  * the number of columns affects the layout only when the
  88  * number of rows is set to zero.
  89  *
  90  * @author  Arthur van Hoff
  91  * @since   1.0


< prev index next >