Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JFrame/8016356/bug8016356.java
38854 views
/*1* Copyright (c) 2013, 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/* @test24@bug 801635625@summary Any swing frame resizes ugly.26@run main bug801635627@author Oleg Pekhovskiy28*/2930import java.awt.AWTException;31import java.awt.Color;32import java.awt.Dimension;33import java.awt.GraphicsConfiguration;34import java.awt.GraphicsEnvironment;35import java.awt.Insets;36import java.awt.Point;37import java.awt.Rectangle;38import java.awt.Robot;39import java.awt.Toolkit;40import java.awt.event.InputEvent;41import javax.swing.JFrame;42import javax.swing.JPanel;43import javax.swing.SwingUtilities;44import sun.awt.OSInfo;4546public class bug8016356 {47private static JFrame frame;48private static Color color;49private static int scrTop;5051private static Point frLoc;52private static Dimension frSize;5354public static void main(String[] args) throws Exception {5556// Windows only test57if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {5859// Retrieving top edge of Desktop60GraphicsConfiguration grConf = GraphicsEnvironment61.getLocalGraphicsEnvironment().getDefaultScreenDevice()62.getDefaultConfiguration();63Rectangle scrRect = grConf.getBounds();64Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(grConf);65scrTop = scrRect.y + scrInsets.top;6667color = new Color(0, 255, 0);6869SwingUtilities.invokeAndWait(() -> {70createAndShowUI();71});7273try {74Robot robot = new Robot();75robot.setAutoDelay(500);76robot.setAutoWaitForIdle(true);77robot.delay(1000);7879// Resizing a window to invoke Windows Snap feature80readFrameInfo();81robot.mouseMove(frLoc.x + frSize.width / 2, frLoc.y);82robot.mousePress(InputEvent.BUTTON1_MASK);83robot.mouseMove(frLoc.x + frSize.width / 2, scrTop);84robot.mouseRelease(InputEvent.BUTTON1_MASK);8586// Retrieving the color of window expanded area87readFrameInfo();88Insets insets = frame.getInsets();89Color bgColor = robot.getPixelColor(frLoc.x + frSize.width / 2,90frLoc.y + frSize.height - insets.bottom - 1);9192frame.dispose();9394if (!bgColor.equals(color)) {95throw new RuntimeException("TEST FAILED: got "96+ bgColor + " instead of " + color);97}98System.out.println("TEST PASSED!");99} catch (AWTException ex) {100throw new RuntimeException("TEST FAILED!");101}102}103}104105private static void createAndShowUI() {106frame = new JFrame();107frame.setBounds(10, scrTop + 10, 300, 100);108JPanel panel = new JPanel();109panel.setBackground(color);110frame.getContentPane().add(panel);111frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);112frame.setVisible(true);113}114115private static void readFrameInfo() throws Exception {116SwingUtilities.invokeAndWait(() -> {117frLoc = frame.getLocationOnScreen();118frSize = frame.getSize();119});120}121}122123124