1 /* 2 * Copyright (c) 2011, 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 /* 25 @test 26 @key headful 27 @bug 7027013 28 @summary Dialog.show() should validate the window unconditionally 29 @author anthony.petrov@oracle.com: area=awt.toplevel 30 @run main ValidateOnShow 31 */ 32 33 import java.awt.*; 34 35 public class ValidateOnShow { 36 private static Dialog dialog = new Dialog((Frame)null); 37 private static Panel panel = new Panel() { 38 @Override 39 public boolean isValidateRoot() { 40 return true; 41 } 42 }; 43 private static Button button = new Button("Test"); 44 45 private static void sleep() { 46 try { Thread.sleep(500); } catch (Exception e) {} 47 } 48 49 private static void test() { 50 System.out.println("Before showing: panel.isValid=" + panel.isValid() + " dialog.isValid=" + dialog.isValid()); 51 dialog.setVisible(true); 52 sleep(); 53 System.out.println("After showing: panel.isValid=" + panel.isValid() + " dialog.isValid=" + dialog.isValid()); 54 55 if (!panel.isValid()) { 56 dialog.dispose(); 57 throw new RuntimeException("The panel hasn't been validated upon showing the dialog"); 58 } 59 60 dialog.setVisible(false); 61 sleep(); 62 } 63 64 public static void main(String[] args) { 65 // setup 66 dialog.add(panel); 67 panel.add(button); 68 69 dialog.setBounds(200, 200, 300, 200); 70 71 // The first test should always succeed since the dialog is invalid initially 72 test(); 73 74 // now invalidate the button and the panel 75 button.setBounds(1, 1, 30, 30); 76 sleep(); 77 // since the panel is a validate root, the dialog is still valid 78 79 // w/o a fix this would fail 80 test(); 81 82 // cleanup 83 dialog.dispose(); 84 } 85 }