Path: blob/master/test/jdk/java/awt/GridBagLayout/GridBagLayoutIpadXYTest/GridBagLayoutIpadXYTest.java
41153 views
/*1* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24@test25@key headful26@bug 500403227@summary GridBagConstraints.ipad(x|y) defined in a new way28@run main GridBagLayoutIpadXYTest29*/3031import java.awt.*;3233public class GridBagLayoutIpadXYTest {34static Frame frame = new Frame();35static TextField jtf = null;36static final int customIpadx = 300;37static final int customIpady = 40;3839public static void main(final String[] args) {40frame.setLayout(new GridBagLayout());41GridBagConstraints gc = new GridBagConstraints();42Insets fieldInsets = new Insets(0,5,5,0);4344gc.anchor = gc.NORTH;45gc.fill = gc.HORIZONTAL;46gc.gridx = 1;47gc.gridy = 0;48gc.weightx = 1;49gc.ipadx = customIpadx;50gc.ipady = customIpady;51gc.insets = fieldInsets;52jtf = new TextField();53frame.add(jtf, gc);5455frame.pack();56frame.setLocationRelativeTo(null);57frame.setVisible(true);5859Robot robot;60try {61robot = new Robot();62robot.waitForIdle();63}catch(Exception ex) {64ex.printStackTrace();65throw new RuntimeException("Unexpected failure");66}6768Dimension minSize = jtf.getMinimumSize();69if ( minSize.width + customIpadx != jtf.getSize().width ||70minSize.height + customIpady != jtf.getSize().height ){71System.out.println("TextField originally has min size = " + jtf.getMinimumSize());72System.out.println("TextField supplied with ipadx = 300, ipady =40");73System.out.println("Frame size: " + frame.getSize());74System.out.println(" Fields's size is "+jtf.getSize());7576throw new RuntimeException("Test Failed. TextField has incorrect width. ");77}78System.out.println("Test Passed.");79}80}818283