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