Path: blob/master/test/jdk/java/awt/Frame/MaximizedToMaximized/MaximizedToMaximized.java
41153 views
/*1* Copyright (c) 2013, 2016, 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*/2223import java.awt.Dimension;24import java.awt.Frame;25import java.awt.GraphicsDevice;26import java.awt.GraphicsEnvironment;27import java.awt.Insets;28import java.awt.Rectangle;29import java.awt.Toolkit;30import java.awt.Robot;3132/**33* @test34* @key headful35* @bug 8007219 814616836* @author Alexander Scherbatiy37* @summary Frame size reverts meaning of maximized attribute38* @run main MaximizedToMaximized39*/40public class MaximizedToMaximized {4142public static void main(String[] args) throws Exception {4344Frame frame = new Frame();45Robot robot = new Robot();46final Toolkit toolkit = Toolkit.getDefaultToolkit();47final GraphicsEnvironment graphicsEnvironment =48GraphicsEnvironment.getLocalGraphicsEnvironment();49final GraphicsDevice graphicsDevice =50graphicsEnvironment.getDefaultScreenDevice();5152final Dimension screenSize = toolkit.getScreenSize();53final Insets screenInsets = toolkit.getScreenInsets(54graphicsDevice.getDefaultConfiguration());5556final Rectangle availableScreenBounds = new Rectangle(screenSize);5758availableScreenBounds.x += screenInsets.left;59availableScreenBounds.y += screenInsets.top;60availableScreenBounds.width -= (screenInsets.left + screenInsets.right);61availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);6263frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,64availableScreenBounds.width, availableScreenBounds.height);65frame.setVisible(true);66robot.waitForIdle();6768Rectangle frameBounds = frame.getBounds();69frame.setExtendedState(Frame.MAXIMIZED_BOTH);70robot.waitForIdle();7172Rectangle maximizedFrameBounds = frame.getBounds();7374frame.dispose();75if (maximizedFrameBounds.width < frameBounds.width76|| maximizedFrameBounds.height < frameBounds.height) {77throw new RuntimeException("Maximized frame is smaller than non maximized");78}79}80}818283