Path: blob/master/test/jdk/java/awt/Frame/MaximizedToUnmaximized/MaximizedToUnmaximized.java
41154 views
/*1* Copyright (c) 2015, 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*/22import java.awt.Frame;23import java.awt.GraphicsConfiguration;24import java.awt.GraphicsEnvironment;25import java.awt.Insets;26import java.awt.Rectangle;27import java.awt.Robot;28import java.awt.Toolkit;2930/**31* @test32* @key headful33* @bug 8065739 812956934* @requires (os.family == "mac")35* @summary [macosx] Frame warps to lower left of screen when displayed36* @author Alexandr Scherbatiy37* @run main MaximizedToUnmaximized38*/39public class MaximizedToUnmaximized {4041public static void main(String[] args) throws Exception {42testFrame(false);43testFrame(true);44}4546static void testFrame(boolean isUndecorated) throws Exception {47Frame frame = new Frame();48try {49Robot robot = new Robot();50robot.setAutoDelay(100);5152frame.setUndecorated(isUndecorated);53GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()54.getDefaultScreenDevice().getDefaultConfiguration();55Rectangle bounds = gc.getBounds();56Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);57int x = bounds.x + insets.left;58int y = bounds.y + insets.top;59int width = bounds.width - insets.left - insets.right;60int height = bounds.height - insets.top - insets.bottom;61Rectangle rect = new Rectangle(x, y, width, height);62frame.pack();63frame.setBounds(rect);64frame.setVisible(true);65robot.waitForIdle();66robot.delay(500);6768if (frame.getWidth() <= width / 269|| frame.getHeight() <= height / 2) {70throw new RuntimeException("Frame size is small!");71}7273if (!isUndecorated && frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {74throw new RuntimeException("Frame state does not equal"75+ " MAXIMIZED_BOTH!");76}77} finally {78frame.dispose();79}80}81}828384