Path: blob/master/test/jdk/javax/swing/JPopupMenu/7160604/bug7160604.java
41155 views
/*1* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@bug 716060425@summary Using non-opaque windows - popups are initially not painted correctly26@author Oleg Pekhovskiy27@run applet/manual=yesno bug7160604.html28*/2930import javax.swing.AbstractAction;31import javax.swing.BorderFactory;32import javax.swing.JApplet;33import javax.swing.JComboBox;34import javax.swing.JLabel;35import javax.swing.JMenuItem;36import javax.swing.JPanel;37import javax.swing.JPopupMenu;38import javax.swing.JWindow;39import javax.swing.SwingUtilities;40import java.awt.*;41import java.awt.event.ActionEvent;42import java.awt.event.MouseAdapter;43import java.awt.event.MouseEvent;44import static java.awt.GraphicsDevice.WindowTranslucency.*;4546public class bug7160604 extends JApplet {4748public void init() {49SwingUtilities.invokeLater(() -> {50if (!GraphicsEnvironment51.getLocalGraphicsEnvironment()52.getDefaultScreenDevice()53.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT)) {54// Tested translucency is not supported. Test passed55return;56}5758final JWindow window = new JWindow();59window.setLocation(200, 200);60window.setSize(300, 300);6162final JLabel label = new JLabel("...click to invoke JPopupMenu");63label.setOpaque(true);64final JPanel contentPane = new JPanel(new BorderLayout());65contentPane.setBorder(BorderFactory.createLineBorder(Color.RED));66window.setContentPane(contentPane);67contentPane.add(label, BorderLayout.NORTH);6869final JComboBox comboBox = new JComboBox(new Object[]{"1", "2", "3", "4"});70contentPane.add(comboBox, BorderLayout.SOUTH);7172final JPopupMenu jPopupMenu = new JPopupMenu();7374jPopupMenu.add("string");75jPopupMenu.add(new AbstractAction("action") {76@Override77public void actionPerformed(final ActionEvent e) {78}79});80jPopupMenu.add(new JLabel("label"));81jPopupMenu.add(new JMenuItem("MenuItem"));82label.addMouseListener(new MouseAdapter() {83@Override84public void mouseReleased(final MouseEvent e) {85jPopupMenu.show(label, 0, 0);86}87});8889window.setBackground(new Color(0, 0, 0, 0));9091window.setVisible(true);92});93}94}959697