Path: blob/master/test/jdk/javax/swing/JInternalFrame/6647340/bug6647340.java
41153 views
/*1* Copyright (c) 2008, 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* @key headful25* @bug 664734026* @summary Checks that iconified internal frame follows27* the main frame borders properly.28* @run main bug664734029*/3031import javax.swing.*;32import java.awt.*;33import java.beans.PropertyVetoException;3435public class bug6647340 {36private JFrame frame;37private volatile Point location;38private volatile Point iconloc;39private JInternalFrame jif;40private static Robot robot;4142public static void main(String[] args) throws Exception {43robot = new Robot();44final bug6647340 test = new bug6647340();45try {46SwingUtilities.invokeAndWait(() -> test.setupUI());47robot.waitForIdle();48robot.delay(1000);49test.test();50} finally {51if (test.frame != null) {52SwingUtilities.invokeAndWait(() -> test.frame.dispose());53}54}55}5657private void setupUI() {58frame = new JFrame();59frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);6061JDesktopPane desktop = new JDesktopPane();62frame.add(desktop);6364jif = new JInternalFrame("Internal Frame", true, true, true, true);65jif.setBounds(20, 20, 200, 100);66desktop.add(jif);67jif.setVisible(true);6869Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();70frame.setBounds((screen.width - 400) / 2, (screen.height - 400) / 2, 400, 400);71frame.setLocationRelativeTo(null);72frame.setVisible(true);73}7475private void test() throws Exception {76test1();7778robot.waitForIdle();79robot.delay(500);80check1();81robot.waitForIdle();8283test2();84robot.waitForIdle();85robot.delay(500);86check2();87}8889private void test1() throws Exception {90SwingUtilities.invokeAndWait(() -> {91setIcon(true);92location = jif.getDesktopIcon().getLocation();93Dimension size = frame.getSize();94frame.setSize(size.width + 100, size.height + 100);95});96}9798private void test2() throws Exception {99SwingUtilities.invokeAndWait(() -> {100setIcon(false);101});102robot.waitForIdle();103robot.delay(500);104105SwingUtilities.invokeAndWait(() -> {106Dimension size = frame.getSize();107frame.setSize(size.width - 100, size.height - 100);108});109robot.waitForIdle();110robot.delay(500);111112SwingUtilities.invokeAndWait(() -> {113setIcon(true);114});115}116117private void check1() throws Exception {118SwingUtilities.invokeAndWait(() -> {119iconloc = jif.getDesktopIcon().getLocation();120});121if (!iconloc.equals(location)) {122System.out.println("First test passed");123} else {124throw new RuntimeException("Icon isn't shifted with the frame bounds");125}126}127128private void check2() throws Exception {129SwingUtilities.invokeAndWait(() -> {130iconloc = jif.getDesktopIcon().getLocation();131});132if (iconloc.equals(location)) {133System.out.println("Second test passed");134} else {135throw new RuntimeException("Icon isn't located near the frame bottom");136}137}138139private void setIcon(boolean b) {140try {141jif.setIcon(b);142} catch (PropertyVetoException e) {143e.printStackTrace();144}145}146}147148149