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