Path: blob/master/test/jdk/sun/java2d/XRSurfaceData/ComponentResizeTest.java
41152 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*/2223import java.awt.Color;24import java.awt.FlowLayout;25import javax.swing.JButton;26import javax.swing.JCheckBox;27import javax.swing.JFrame;28import javax.swing.SwingUtilities;29import java.awt.Component;30import javax.swing.JOptionPane;3132/**33* @test34* @bug 803934535* @author Prasanta Sadhukhan36* @run main/manual ComponentResizeTest37* @summary Resizes JFrame so that component drawn inside it gets repainted38* without leaving any trails39*/40public class ComponentResizeTest {4142private static JFrame demoFrame;4344public static void testresize() throws Exception {45Thread.sleep(5000);46for (int i = 0; i < 20; i++) {47SwingUtilities.invokeLater(() -> {48demoFrame.setSize(demoFrame.getWidth() + 5, demoFrame.getHeight() + 5);49});50Thread.sleep(1000);51}52}5354public static void main(String[] args) throws Exception {55SwingUtilities.invokeAndWait(() -> {56JOptionPane.showMessageDialog(57(Component) null,58"The test creates a transparent JFrame and resizes the JFrame. Please verify JFrame is transparent and components (like JButton, checkbox) move without leaving any trails",59"information", JOptionPane.INFORMATION_MESSAGE);60createAndShowGUI();61});6263try {64testresize();65} finally {66SwingUtilities.invokeLater(() -> {67demoFrame.dispose();68});69}7071SwingUtilities.invokeAndWait(() -> {72int confirm = JOptionPane.showConfirmDialog(73(Component) null,74"Did the component resize work without leaving any trails?",75"alert", JOptionPane.YES_NO_OPTION);76if (confirm == JOptionPane.YES_OPTION) {77System.out.println("Test passed");78} else {79System.out.println("Test failed");80throw new RuntimeException("Component resize leaves trail");81}82});83}8485private static void createAndShowGUI() {86demoFrame = new JFrame();87demoFrame.setSize(300, 300);88demoFrame.setLayout(new FlowLayout());89demoFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);90demoFrame.setUndecorated(true);91demoFrame.setBackground(new Color(0f, 0, 0, 0.1f));92JCheckBox b = new JCheckBox("Whatever");93demoFrame.paintAll(null);94b.setOpaque(true);95demoFrame.add(b);96demoFrame.add(new JButton());97demoFrame.setVisible(true);98}99}100101102