Path: blob/master/test/jdk/java/awt/Frame/SetMinimumSizeTest/SetMinimumSizeTest2.java
66645 views
/*1* Copyright (c) 2022, 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* @summary Verify frame resizes back to minimumSize on calling pack27* @run main SetMinimumSizeTest228*/2930import java.awt.Button;31import java.awt.Dimension;32import java.awt.EventQueue;33import java.awt.Frame;34import java.awt.Robot;3536public class SetMinimumSizeTest2 {3738private static Frame frame;39private static volatile Dimension dimension;40private static volatile Dimension actualDimension;4142public static void createGUI() {43frame = new Frame();44frame.add(new Button("Button"));45frame.setMinimumSize(new Dimension(140, 140));46frame.setLocationRelativeTo(null);47frame.setVisible(true);48}4950public static void doTest() throws Exception {51try {52EventQueue.invokeAndWait(() -> createGUI());5354Robot robot = new Robot();55robot.setAutoDelay(100);56robot.waitForIdle();5758EventQueue.invokeAndWait(() -> {59dimension = frame.getSize();60});6162EventQueue.invokeAndWait(() -> {63frame.setSize(dimension.width + 20, dimension.height + 20);64frame.invalidate();65frame.validate();66});6768robot.waitForIdle();6970EventQueue.invokeAndWait(() -> {71frame.pack();72frame.invalidate();73frame.validate();74});7576robot.waitForIdle();7778EventQueue.invokeAndWait(() -> {79actualDimension = frame.getSize();80});8182if (!actualDimension.equals(dimension)) {83throw new RuntimeException("Test Failed\n"84+ "expected dimension:(" + dimension.width + "," + dimension.height +")\n"85+ "actual dimension:(" + actualDimension.width + "," + actualDimension.height + ")");86}87} finally {88EventQueue.invokeAndWait(() -> frame.dispose());89}90}9192public static void main(String[] args) throws Exception {93doTest();94}95}96979899