1 /* 2 * Copyright (c) 2013, 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 /* @test 25 @bug 7160604 26 @summary Using non-opaque windows - popups are initially not painted correctly 27 @author Oleg Pekhovskiy 28 @run applet/manual=yesno bug7160604.html 29 */ 30 31 import javax.swing.AbstractAction; 32 import javax.swing.BorderFactory; 33 import javax.swing.JApplet; 34 import javax.swing.JComboBox; 35 import javax.swing.JLabel; 36 import javax.swing.JMenuItem; 37 import javax.swing.JPanel; 38 import javax.swing.JPopupMenu; 39 import javax.swing.JWindow; 40 import javax.swing.SwingUtilities; 41 import java.awt.BorderLayout; 42 import java.awt.Color; 43 import java.awt.event.ActionEvent; 44 import java.awt.event.MouseAdapter; 45 import java.awt.event.MouseEvent; 46 47 public class bug7160604 extends JApplet { 48 49 public void init() { 50 SwingUtilities.invokeLater(() -> { 51 final JWindow window = new JWindow(); 52 window.setLocation(200, 200); 53 window.setSize(300, 300); 54 55 final JLabel label = new JLabel("...click to invoke JPopupMenu"); 56 label.setOpaque(true); 57 final JPanel contentPane = new JPanel(new BorderLayout()); 58 contentPane.setBorder(BorderFactory.createLineBorder(Color.RED)); 59 window.setContentPane(contentPane); 60 contentPane.add(label, BorderLayout.NORTH); 61 62 final JComboBox comboBox = new JComboBox(new Object[]{"1", "2", "3", "4"}); 63 contentPane.add(comboBox, BorderLayout.SOUTH); 64 65 final JPopupMenu jPopupMenu = new JPopupMenu(); 66 67 jPopupMenu.add("string"); 68 jPopupMenu.add(new AbstractAction("action") { 69 @Override 70 public void actionPerformed(final ActionEvent e) { 71 } 72 }); 73 jPopupMenu.add(new JLabel("label")); 74 jPopupMenu.add(new JMenuItem("MenuItem")); 75 label.addMouseListener(new MouseAdapter() { 76 @Override 77 public void mouseReleased(final MouseEvent e) { 78 jPopupMenu.show(label, 0, 0); 79 } 80 }); 81 82 window.setBackground(new Color(0, 0, 0, 0)); 83 84 window.setVisible(true); 85 }); 86 } 87 }