Path: blob/master/test/jdk/javax/swing/JInternalFrame/4769772/TestJInternalFrameIconify.java
41153 views
/*1* Copyright (c) 2015, 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 476977227* @summary JInternalFrame.setIcon(true) before JDesktopPane.add(JIF) causes wrong state28* @run main TestJInternalFrameIconify29*/30import java.beans.PropertyVetoException;31import javax.swing.JFrame;32import javax.swing.JDesktopPane;33import javax.swing.JInternalFrame;34import javax.swing.UIManager;35import javax.swing.UnsupportedLookAndFeelException;36import java.awt.Robot;37import javax.swing.SwingUtilities;3839public class TestJInternalFrameIconify {4041private static JDesktopPane desktopPane;42private static JFrame frame;43private static Robot robot;44private static volatile String errorMessage = "";4546public static void main(String[] args) throws Exception {47robot = new java.awt.Robot();48UIManager.LookAndFeelInfo[] lookAndFeelArray49= UIManager.getInstalledLookAndFeels();50for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {51String lookAndFeelString = lookAndFeelItem.getClassName();52if (tryLookAndFeel(lookAndFeelString)) {53createUI(lookAndFeelString);54robot.waitForIdle();55executeTest(lookAndFeelString);56}57}58if (!"".equals(errorMessage)) {59throw new RuntimeException(errorMessage);60}61}6263private static boolean tryLookAndFeel(String lookAndFeelString) {64try {65UIManager.setLookAndFeel(lookAndFeelString);66return true;67} catch (UnsupportedLookAndFeelException | ClassNotFoundException |68InstantiationException | IllegalAccessException e) {69errorMessage += e.getMessage() + "\n";70System.err.println("Caught Exception: " + e.getMessage());71return false;72}73}7475private static void createUI(String lookAndFeelString) throws Exception {76SwingUtilities.invokeAndWait(new Runnable() {77@Override78public void run() {79frame = new JFrame(lookAndFeelString);80desktopPane = new JDesktopPane();81frame.getContentPane().add(desktopPane);82frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);8384JInternalFrame f = new JInternalFrame("Child ", true, true,85true, true);86f.setSize(200, 300);87f.setLocation(20, 20);88try {89f.setIcon(true);90} catch (PropertyVetoException ex) {91errorMessage += ex.getMessage() + "\n";92}93desktopPane.add(f);94f.setVisible(true);9596frame.setSize(500, 500);97frame.setLocationRelativeTo(null);98frame.setVisible(true);99}100});101102}103104private static void executeTest(String lookAndFeelString) throws Exception {105SwingUtilities.invokeAndWait(new Runnable() {106107@Override108public void run() {109try {110JInternalFrame internalFrames[]111= desktopPane.getAllFrames();112if (internalFrames[0].isShowing()) {113errorMessage += "Test Failed for "114+ lookAndFeelString + " look and feel\n";115System.err.println(errorMessage);116}117} finally {118frame.dispose();119}120}121});122}123}124125126