1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.awt.BorderLayout; 25 import java.awt.Color; 26 import java.awt.FlowLayout; 27 import java.awt.Graphics; 28 import java.awt.Window; 29 import java.awt.event.ComponentEvent; 30 import java.awt.event.ComponentListener; 31 import java.awt.event.ContainerAdapter; 32 import java.awt.event.WindowStateListener; 33 import java.util.logging.Level; 34 import java.util.logging.Logger; 35 import javax.swing.JButton; 36 import javax.swing.JCheckBox; 37 import javax.swing.JFrame; 38 39 import java.awt.Component; 40 import javax.swing.JOptionPane; 41 42 /** 43 * @test 44 * @bug 8039345 45 * @author Prasanta Sadhukhan 46 * @run main/manual ComponentResizeTest 47 * @summary Resizes JFrame so that component drawn inside it gets repainted 48 * without leaving any trails 49 */ 50 public class ComponentResizeTest extends JFrame{ 51 static final JFrame demoFrame = new JFrame(); 52 53 public static void testresize() { 54 55 try { 56 Thread.sleep(5000); 57 for (int i = 0; i < 20; i++) { 58 demoFrame.setSize(demoFrame.getWidth() + 5, demoFrame.getHeight() + 5); 59 Thread.sleep(1000); 60 61 } 62 } catch (InterruptedException ex) { 63 Logger.getLogger(ComponentResizeTest.class.getName()).log(Level.SEVERE, null, ex); 64 } 65 int confirm = JOptionPane.showConfirmDialog( 66 (Component) null, 67 "Did the component resize work without leaving any trails?", 68 "alert", JOptionPane.YES_NO_OPTION); 69 if (confirm == JOptionPane.YES_OPTION) { 70 System.out.println("Test passed"); 71 } else { 72 System.out.println("Test failed"); 73 throw new RuntimeException("Component resize leaves trail"); 74 } 75 } 76 77 public static void main(String[] args) throws Exception { 78 demoFrame.setSize(300, 300); 79 demoFrame.setLayout(new FlowLayout()); 80 demoFrame.setDefaultCloseOperation(EXIT_ON_CLOSE); 81 demoFrame.setUndecorated(true); 82 demoFrame.setBackground(new Color(0f, 0, 0, 0.1f)); 83 JCheckBox b = new JCheckBox("Whatever"); 84 demoFrame.paintAll(null); 85 b.setOpaque(true); 86 demoFrame.add(b); 87 demoFrame.add(new JButton()); 88 demoFrame.setVisible(true); 89 90 try { 91 testresize(); 92 } finally { 93 demoFrame.dispose(); 94 } 95 } 96 } 97