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   @key headful
  27   @bug 5004032
  28   @summary GridBagConstraints.ipad(x|y) defined in a new way
  29   @run main GridBagLayoutIpadXYTest
  30 */
  31 
  32 import java.awt.*;
  33 
  34 public class GridBagLayoutIpadXYTest {
  35     static Frame frame = new Frame();
  36     static TextField jtf = null;
  37     static final int customIpadx = 300;
  38     static final int customIpady = 40;
  39 
  40     public static void main(final String[] args) {
  41         frame.setLayout(new GridBagLayout());
  42         GridBagConstraints gc = new GridBagConstraints();
  43         Insets fieldInsets = new Insets(0,5,5,0);
  44 
  45         gc.anchor = gc.NORTH;
  46         gc.fill = gc.HORIZONTAL;
  47         gc.gridx = 1;
  48         gc.gridy = 0;
  49         gc.weightx = 1;
  50         gc.ipadx = customIpadx;
  51         gc.ipady = customIpady;
  52         gc.insets = fieldInsets;
  53         jtf = new TextField();
  54         frame.add(jtf, gc);
  55 
  56         frame.pack();
  57         frame.setLocationRelativeTo(null);
  58         frame.setVisible(true);
  59 
  60         Robot robot;
  61         try {
  62             robot = new Robot();
  63             robot.waitForIdle();
  64         }catch(Exception ex) {
  65             ex.printStackTrace();
  66             throw new RuntimeException("Unexpected failure");
  67         }
  68 
  69         Dimension minSize = jtf.getMinimumSize();
  70         if ( minSize.width + customIpadx != jtf.getSize().width ||
  71              minSize.height + customIpady != jtf.getSize().height ){
  72             System.out.println("TextField originally has min size = " + jtf.getMinimumSize());
  73             System.out.println("TextField supplied with ipadx =  300, ipady =40");
  74             System.out.println("Frame size: " + frame.getSize());
  75             System.out.println(" Fields's size is "+jtf.getSize());
  76 
  77             throw new RuntimeException("Test Failed. TextField has incorrect width. ");
  78         }
  79         System.out.println("Test Passed.");
  80     }
  81 }