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 TextArea 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.TextArea; 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 TextArea textArea = 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 61 SwingUtilities.invokeAndWait(new Runnable() { 62 @Override 63 public void run() { 64 frame = new JFrame("Test"); 65 66 textArea = new TextArea("editable textArea"); 67 textArea.setEditable(true); 68 // textArea.setEditable(false); // this testcase passes if textArea is non-editable 69 70 frame.setLayout(new FlowLayout()); 71 frame.add(textArea); 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 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 }