Path: blob/master/test/jdk/javax/swing/JFrame/8016356/bug8016356.java
41154 views
/*1* Copyright (c) 2013, 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*/2223/**24* @test25* @key headful26* @bug 801635627* @summary Any swing frame resizes ugly.28* @author Oleg Pekhovskiy29* @requires (os.family == "windows")30* @library /test/lib31* @build jdk.test.lib.Platform32* @run main bug801635633*/3435import java.awt.AWTException;36import java.awt.Color;37import java.awt.Dimension;38import java.awt.GraphicsConfiguration;39import java.awt.GraphicsEnvironment;40import java.awt.Insets;41import java.awt.Point;42import java.awt.Rectangle;43import java.awt.Robot;44import java.awt.Toolkit;45import java.awt.event.InputEvent;46import javax.swing.JFrame;47import javax.swing.JPanel;48import javax.swing.SwingUtilities;4950import jdk.test.lib.Platform;5152public class bug8016356 {53private static JFrame frame;54private static Color color;55private static int scrTop;5657private static Point frLoc;58private static Dimension frSize;5960public static void main(String[] args) throws Exception {6162// Windows only test63if (Platform.isWindows()) {6465// Retrieving top edge of Desktop66GraphicsConfiguration grConf = GraphicsEnvironment67.getLocalGraphicsEnvironment().getDefaultScreenDevice()68.getDefaultConfiguration();69Rectangle scrRect = grConf.getBounds();70Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(grConf);71scrTop = scrRect.y + scrInsets.top;7273color = new Color(0, 255, 0);7475SwingUtilities.invokeAndWait(() -> {76createAndShowUI();77});7879try {80Robot robot = new Robot();81robot.setAutoDelay(500);82robot.setAutoWaitForIdle(true);83robot.delay(1000);8485// Resizing a window to invoke Windows Snap feature86readFrameInfo();87robot.mouseMove(frLoc.x + frSize.width / 2, frLoc.y);88robot.mousePress(InputEvent.BUTTON1_MASK);89robot.mouseMove(frLoc.x + frSize.width / 2, scrTop);90robot.mouseRelease(InputEvent.BUTTON1_MASK);9192// Retrieving the color of window expanded area93readFrameInfo();94Insets insets = frame.getInsets();95Color bgColor = robot.getPixelColor(frLoc.x + frSize.width / 2,96frLoc.y + frSize.height - insets.bottom - 1);9798frame.dispose();99100if (!bgColor.equals(color)) {101throw new RuntimeException("TEST FAILED: got "102+ bgColor + " instead of " + color);103}104System.out.println("TEST PASSED!");105} catch (AWTException ex) {106throw new RuntimeException("TEST FAILED!");107}108}109}110111private static void createAndShowUI() {112frame = new JFrame();113frame.setBounds(10, scrTop + 10, 300, 100);114JPanel panel = new JPanel();115panel.setBackground(color);116frame.getContentPane().add(panel);117frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);118frame.setVisible(true);119}120121private static void readFrameInfo() throws Exception {122SwingUtilities.invokeAndWait(() -> {123frLoc = frame.getLocationOnScreen();124frSize = frame.getSize();125});126}127}128129130