1 /* 2 * Copyright (c) 2006, 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 @bug 6359129 27 @summary REGRESSION: Popup menus dont respond to selections when extend outside Applet 28 @author oleg.sukhodolsky area=awt.grab 29 @modules java.desktop/java.awt.peer 30 java.desktop/sun.awt 31 @library ../../regtesthelpers 32 @build Util UtilInternal 33 @run main EmbeddedFrameTest1 34 */ 35 36 /** 37 * EmbeddedFrameTest1.java 38 * 39 * summary: REGRESSION: Popup menus dont respond to selections when extend outside Applet 40 */ 41 42 import java.awt.BorderLayout; 43 import java.awt.Dialog; 44 import java.awt.Frame; 45 import java.awt.Panel; 46 import java.awt.Robot; 47 import java.awt.TextArea; 48 import java.awt.Toolkit; 49 import java.awt.AWTException; 50 51 import java.awt.event.ActionEvent; 52 import java.awt.event.ActionListener; 53 54 import javax.swing.JButton; 55 import javax.swing.JPopupMenu; 56 57 import test.java.awt.regtesthelpers.Util; 58 import test.java.awt.regtesthelpers.UtilInternal; 59 60 public class EmbeddedFrameTest1 61 { 62 public static void main( String args[] ) throws AWTException 63 { 64 try { 65 final Frame frame = new Frame("AWT Frame"); 66 frame.pack(); 67 frame.setSize(200,200); 68 69 final Frame embedded_frame = UtilInternal.createEmbeddedFrame(frame); 70 embedded_frame.setSize(200, 200); 71 System.out.println("embedded_frame = " + embedded_frame); 72 73 final JPopupMenu menu = new JPopupMenu(); 74 JButton item = new JButton("A button in popup"); 75 item.addActionListener(new ActionListener() { 76 public void actionPerformed(ActionEvent e) { 77 System.out.println("Button pressed"); 78 } 79 }); 80 81 menu.add(item); 82 83 final JButton btn = new JButton("Press me to see popup"); 84 btn.addActionListener(new ActionListener() { 85 public void actionPerformed(ActionEvent e) { 86 menu.show(btn, 0, btn.getHeight()); 87 } 88 }); 89 final Panel p = new Panel(); 90 p.setLayout(new BorderLayout()); 91 embedded_frame.add(p,BorderLayout.CENTER); 92 embedded_frame.validate(); 93 p.add(btn); 94 p.validate(); 95 frame.setVisible(true); 96 Robot robot = new Robot(); 97 robot.waitForIdle(); 98 Util.clickOnComp(btn, robot); 99 robot.waitForIdle(); 100 101 Util.clickOnComp(item, robot); 102 robot.waitForIdle(); 103 if (item.getMousePosition() == null) { 104 throw new RuntimeException("Popup was not closed (mouse above it)"); 105 } 106 embedded_frame.remove(p); 107 embedded_frame.dispose(); 108 frame.dispose(); 109 } catch (Throwable thr) { 110 thr.printStackTrace(); 111 throw new RuntimeException("TEST FAILED: " + thr); 112 } 113 } 114 }