jdk/test/java/awt/GridBagLayout/GridBagLayoutIpadXYTest/GridBagLayoutIpadXYTest.java
changeset 3087 e5f156d403ad
child 5506 202f599c92aa
equal deleted inserted replaced
3086:1088cc6368b7 3087:e5f156d403ad
       
     1 /*
       
     2  * Copyright 2009 Sun Microsystems, Inc.  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.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  */
       
    23 
       
    24 /*
       
    25   test
       
    26   @bug 5004032
       
    27   @summary GridBagConstraints.ipad(x|y) defined in a new way
       
    28   @author dav@sparc.spb.su area=
       
    29   @run applet GridBagLayoutIpadXYTest.html
       
    30 */
       
    31 
       
    32 import java.applet.Applet;
       
    33 import java.awt.*;
       
    34 
       
    35 public class GridBagLayoutIpadXYTest extends Applet
       
    36 {
       
    37     Frame frame = new Frame();
       
    38     TextField jtf = null;
       
    39     final int customIpadx = 300;
       
    40     final int customIpady = 40;
       
    41 
       
    42     public void init()
       
    43     {
       
    44         this.setLayout (new BorderLayout ());
       
    45 
       
    46         String[] instructions =
       
    47         {
       
    48             "This is an AUTOMATIC test",
       
    49             "simply wait until it is done"
       
    50         };
       
    51     }//End  init()
       
    52 
       
    53     public void start ()
       
    54     {
       
    55         validate();
       
    56         frame.setLayout(new GridBagLayout());
       
    57         GridBagConstraints gc = new GridBagConstraints();
       
    58         Insets fieldInsets = new Insets(0,5,5,0);
       
    59 
       
    60         gc.anchor = gc.NORTH;
       
    61         gc.fill = gc.HORIZONTAL;
       
    62         gc.gridx = 1;
       
    63         gc.gridy = 0;
       
    64         gc.weightx = 1;
       
    65         gc.ipadx = customIpadx;
       
    66         gc.ipady = customIpady;
       
    67         gc.insets = fieldInsets;
       
    68         jtf = new TextField();
       
    69         frame.add(jtf, gc);
       
    70 
       
    71         frame.pack();
       
    72         frame.setVisible(true);
       
    73 
       
    74         ((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync();
       
    75 
       
    76         Dimension minSize = jtf.getMinimumSize();
       
    77         if ( minSize.width + customIpadx != jtf.getSize().width ||
       
    78              minSize.height + customIpady != jtf.getSize().height ){
       
    79             System.out.println("TextField originally has min size = " + jtf.getMinimumSize());
       
    80             System.out.println("TextField supplied with ipadx =  300, ipady =40");
       
    81             System.out.println("Frame size: " + frame.getSize());
       
    82             System.out.println(" Fields's size is "+jtf.getSize());
       
    83 
       
    84             throw new RuntimeException("Test Failed. TextField has incorrect width. ");
       
    85         }
       
    86         System.out.println("Test Passed.");
       
    87 
       
    88     }// start()
       
    89 }