Path: blob/master/test/jdk/java/awt/Container/MoveToOtherScreenTest/MoveToOtherScreenTest.java
41154 views
/*1* Copyright (c) 2016, 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 javax.swing.JFrame;24import javax.swing.SwingUtilities;25import java.awt.Canvas;26import java.awt.Color;27import java.awt.Dimension;28import java.awt.Frame;29import java.awt.GraphicsConfiguration;30import java.awt.GraphicsDevice;31import java.awt.GraphicsEnvironment;32import java.lang.reflect.InvocationTargetException;33343536/* @test37@bug 816069638@summary IllegalArgumentException: adding a component to a container on a different GraphicsDevice39@author Mikhail Cherkasov40@run main MoveToOtherScreenTest41@key headful42*/43public class MoveToOtherScreenTest {4445private static volatile boolean twoDisplays = true;46private static final Canvas canvas = new Canvas();47private static final Frame[] frms = new JFrame[2];4849public static void main(String[] args) throws InterruptedException, InvocationTargetException {50SwingUtilities.invokeAndWait(new Runnable() {51public void run() {52GraphicsEnvironment ge = GraphicsEnvironment.53getLocalGraphicsEnvironment();54GraphicsDevice[] gds = ge.getScreenDevices();55if (gds.length < 2) {56System.out.println("Test requires at least 2 displays");57twoDisplays = false;58return;59}60for (int i = 0; i < 2; i++) {61GraphicsConfiguration conf = gds[i].getConfigurations()[0];62JFrame frm = new JFrame("Frame " + i);63frm.setLocation(conf.getBounds().x, 0); // On first screen64frm.setSize(new Dimension(400, 400));65frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);66frm.setVisible(true);67frms[i] = frm;68}69canvas.setBackground(Color.red);70frms[0].add(canvas);71}72});73if(!twoDisplays){74return;75}76Thread.sleep(200);77SwingUtilities.invokeAndWait(new Runnable() {78@Override79public void run() {80frms[1].add(canvas);81}82});83for (Frame frm : frms) {84frm.dispose();85}86}87}888990