Path: blob/master/test/jdk/java/awt/Frame/MaximizedToOppositeScreen/MaximizedToOppositeScreenSmall.java
41153 views
/*1* Copyright (c) 2020, 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.Rectangle;28import java.awt.Robot;29import java.awt.Toolkit;3031/**32* @test33* @bug 8176359 8231564 821199934* @key headful35* @requires (os.family == "windows" | os.family == "mac")36* @summary setMaximizedBounds() should work if set to the screen other than37* current screen of the Frame, the size of the frame is intentionally38* small39*/40public final class MaximizedToOppositeScreenSmall {4142public static void main(String[] args) throws Exception {43//Supported platforms are Windows and OS X.44String os = System.getProperty("os.name").toLowerCase();45if (!os.contains("windows") && !os.contains("os x")) {46return;47}4849if (!Toolkit.getDefaultToolkit().50isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {51return;52}5354var ge = GraphicsEnvironment.getLocalGraphicsEnvironment();55GraphicsDevice[] gds = ge.getScreenDevices();56Robot robot = new Robot();57for (GraphicsDevice gd1 : gds) {58Rectangle framAt = gd1.getDefaultConfiguration().getBounds();59framAt.grow(-framAt.width / 2 + 100, -framAt.height / 2 + 100);60for (GraphicsDevice gd2 : gds) {61Frame frame = new Frame(gd1.getDefaultConfiguration());62try {63frame.setLayout(null); // trigger use the minimum size of64// the peer65frame.setBounds(framAt);6667frame.setVisible(true);68robot.waitForIdle();69robot.delay(1000);7071Dimension minimumSize = frame.getMinimumSize();72minimumSize.width = Math.max(minimumSize.width, 120);73minimumSize.height = Math.max(minimumSize.height, 120);74Rectangle maxTo = gd2.getDefaultConfiguration().getBounds();75maxTo.grow(-maxTo.width / 2 + minimumSize.width,76-maxTo.height / 2 + minimumSize.height);7778frame.setMaximizedBounds(maxTo);79frame.setExtendedState(Frame.MAXIMIZED_BOTH);80robot.waitForIdle();81robot.delay(1000);8283Rectangle actual = frame.getBounds();84if (!actual.equals(maxTo)) {85System.err.println("Actual: " + actual);86System.err.println("Expected: " + maxTo);87throw new RuntimeException("Wrong bounds");88}89} finally {90frame.dispose();91}92}93}94}95}96979899