Path: blob/master/test/jdk/java/awt/Frame/SetMinimumSizeTest/SetMinimumSizeTest1.java
66646 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 that increase in Frame's minimumSize gets reflected in the subsequent getSize call27* @run main SetMinimumSizeTest128*/2930import java.awt.Button;31import java.awt.Dimension;32import java.awt.EventQueue;33import java.awt.Frame;34import java.awt.Robot;3536public class SetMinimumSizeTest1 {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.setSize(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();60dimension.width += 20;61dimension.height += 20;62frame.setMinimumSize(dimension);63frame.invalidate();64frame.validate();65});6667robot.waitForIdle();6869EventQueue.invokeAndWait(() -> {70actualDimension = frame.getSize();71});7273if (!actualDimension.equals(dimension)) {74throw new RuntimeException("Test Failed\n"75+ "expected dimension:(" + dimension.width + "," + dimension.height +")\n"76+ "actual dimension:(" + actualDimension.width + "," + actualDimension.height + ")");77}78} finally {79EventQueue.invokeAndWait(() -> frame.dispose());80}81}8283public static void main(String[] args) throws Exception {84doTest();85}86}87888990