1/* 2 * Copyright (c) 2009, 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 32import java.applet.Applet; 33import java.awt.*; 34 35public 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 Robot robot; 75 try { 76 robot = new Robot(); 77 robot.waitForIdle(); 78 }catch(Exception ex) { 79 ex.printStackTrace(); 80 throw new RuntimeException("Unexpected failure"); 81 } 82 83 Dimension minSize = jtf.getMinimumSize(); 84 if ( minSize.width + customIpadx != jtf.getSize().width || 85 minSize.height + customIpady != jtf.getSize().height ){ 86 System.out.println("TextField originally has min size = " + jtf.getMinimumSize()); 87 System.out.println("TextField supplied with ipadx = 300, ipady =40"); 88 System.out.println("Frame size: " + frame.getSize()); 89 System.out.println(" Fields's size is "+jtf.getSize()); 90 91 throw new RuntimeException("Test Failed. TextField has incorrect width. "); 92 } 93 System.out.println("Test Passed."); 94 95 }// start() 96} 97