Path: blob/master/test/jdk/java/awt/Frame/MaximizedToOppositeScreen/MaximizedToOppositeScreenBig.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.Frame;24import java.awt.GraphicsDevice;25import java.awt.GraphicsEnvironment;26import java.awt.Rectangle;27import java.awt.Robot;28import java.awt.Toolkit;2930/**31* @test32* @bug 8176359 823156433* @key headful34* @requires (os.family == "windows" | os.family == "mac")35* @summary setMaximizedBounds() should work if set to the screen other than36* current screen of the Frame, the size of the frame is intentionally37* big38* @run main/othervm MaximizedToOppositeScreenBig39* @run main/othervm -Dsun.java2d.uiScale=1 MaximizedToOppositeScreenBig40* @run main/othervm -Dsun.java2d.uiScale=1.2 MaximizedToOppositeScreenBig41* @run main/othervm -Dsun.java2d.uiScale=1.25 MaximizedToOppositeScreenBig42* @run main/othervm -Dsun.java2d.uiScale=1.5 MaximizedToOppositeScreenBig43* @run main/othervm -Dsun.java2d.uiScale=1.75 MaximizedToOppositeScreenBig44* @run main/othervm -Dsun.java2d.uiScale=2 MaximizedToOppositeScreenBig45* @run main/othervm -Dsun.java2d.uiScale=2.25 MaximizedToOppositeScreenBig46*/47public final class MaximizedToOppositeScreenBig {4849public static void main(String[] args) throws Exception {50//Supported platforms are Windows and OS X.51String os = System.getProperty("os.name").toLowerCase();52if (!os.contains("windows") && !os.contains("os x")) {53return;54}5556if (!Toolkit.getDefaultToolkit().57isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {58return;59}6061var ge = GraphicsEnvironment.getLocalGraphicsEnvironment();62GraphicsDevice[] gds = ge.getScreenDevices();63Robot robot = new Robot();64for (GraphicsDevice gd1 : gds) {65Rectangle framAt = gd1.getDefaultConfiguration().getBounds();66framAt.grow(-200, -200);67for (GraphicsDevice gd2 : gds) {68Rectangle maxTo = gd2.getDefaultConfiguration().getBounds();69maxTo.grow(-150, -150);70Frame frame = new Frame(gd1.getDefaultConfiguration());71try {72frame.setBounds(framAt);73frame.setVisible(true);74robot.waitForIdle();75robot.delay(1000);7677frame.setMaximizedBounds(maxTo);78frame.setExtendedState(Frame.MAXIMIZED_BOTH);79robot.waitForIdle();80robot.delay(1000);8182Rectangle actual = frame.getBounds();83if (!actual.equals(maxTo)) {84System.err.println("Actual: " + actual);85System.err.println("Expected: " + maxTo);86throw new RuntimeException("Wrong bounds");87}88} finally {89frame.dispose();90}91}92}93}94}95969798