1 /*
   2  * Copyright (c) 2009, 2018, 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.
   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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * 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     }//End  init()
  47 
  48     public void start ()
  49     {
  50         validate();
  51         frame.setLayout(new GridBagLayout());
  52         GridBagConstraints gc = new GridBagConstraints();
  53         Insets fieldInsets = new Insets(0,5,5,0);
  54 
  55         gc.anchor = gc.NORTH;
  56         gc.fill = gc.HORIZONTAL;
  57         gc.gridx = 1;
  58         gc.gridy = 0;
  59         gc.weightx = 1;
  60         gc.ipadx = customIpadx;
  61         gc.ipady = customIpady;
  62         gc.insets = fieldInsets;
  63         jtf = new TextField();
  64         frame.add(jtf, gc);
  65 
  66         frame.pack();
  67         frame.setVisible(true);
  68 
  69         Robot robot;
  70         try {
  71             robot = new Robot();
  72             robot.waitForIdle();
  73         }catch(Exception ex) {
  74             ex.printStackTrace();
  75             throw new RuntimeException("Unexpected failure");
  76         }
  77 
  78         Dimension minSize = jtf.getMinimumSize();
  79         if ( minSize.width + customIpadx != jtf.getSize().width ||
  80              minSize.height + customIpady != jtf.getSize().height ){
  81             System.out.println("TextField originally has min size = " + jtf.getMinimumSize());
  82             System.out.println("TextField supplied with ipadx =  300, ipady =40");
  83             System.out.println("Frame size: " + frame.getSize());
  84             System.out.println(" Fields's size is "+jtf.getSize());
  85 
  86             throw new RuntimeException("Test Failed. TextField has incorrect width. ");
  87         }
  88         System.out.println("Test Passed.");
  89 
  90     }// start()
  91 }