1 /* 2 * Copyright (c) 2012, 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 * Portions Copyright (c) 2012 IBM Corporation 26 */ 27 28 /* @test 29 * @bug 7155298 30 * @key headful 31 * @run main/othervm/timeout=60 TestDispose 32 * @summary Editable TextField blocks GUI application from exit. 33 * @author Sean Chou 34 */ 35 36 import java.awt.FlowLayout; 37 import java.awt.Frame; 38 import java.awt.TextField; 39 import java.awt.Robot; 40 import java.lang.reflect.InvocationTargetException; 41 42 import javax.swing.JFrame; 43 import javax.swing.SwingUtilities; 44 45 public class TestDispose { 46 47 public static Frame frame = null; 48 public static TextField textField = null; 49 public static volatile Process worker = null; 50 51 public void testDispose() throws InvocationTargetException, 52 InterruptedException { 53 Robot robot; 54 try { 55 robot = new Robot(); 56 }catch(Exception ex) { 57 ex.printStackTrace(); 58 throw new RuntimeException("Unexpected failure"); 59 } 60 61 SwingUtilities.invokeAndWait(new Runnable() { 62 @Override 63 public void run() { 64 frame = new JFrame("Test"); 65 66 textField = new TextField("editable textArea"); 67 textField.setEditable(true); 68 // textField.setEditable(false); // this testcase passes if textField is non-editable 69 70 frame.setLayout(new FlowLayout()); 71 frame.add(textField); 72 73 frame.pack(); 74 frame.setVisible(true); 75 } 76 }); 77 robot.waitForIdle(); 78 79 SwingUtilities.invokeAndWait(new Runnable() { 80 @Override 81 public void run() { 82 frame.dispose(); 83 } 84 }); 85 robot.waitForIdle(); 86 87 } 88 89 public static void main(String[] args) throws Exception{ 90 if(args.length == 0) { 91 Runtime.getRuntime().addShutdownHook(new Thread(){ 92 public void run() { 93 worker.destroy(); 94 } 95 }); 96 97 System.out.println(System.getProperty("java.home")+"/bin/java TestDispose workprocess"); 98 worker = Runtime.getRuntime().exec(System.getProperty("java.home")+"/bin/java TestDispose workprocess"); 99 worker.waitFor(); 100 return; 101 } 102 103 TestDispose app = new TestDispose(); 104 app.testDispose(); 105 } 106 107 }