Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JPopupMenu/7160604/bug7160604.java
38854 views
/*1* Copyright (c) 2013, 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.BorderLayout;41import java.awt.Color;42import java.awt.event.ActionEvent;43import java.awt.event.MouseAdapter;44import java.awt.event.MouseEvent;4546public class bug7160604 extends JApplet {4748public void init() {49SwingUtilities.invokeLater(() -> {50final JWindow window = new JWindow();51window.setLocation(200, 200);52window.setSize(300, 300);5354final JLabel label = new JLabel("...click to invoke JPopupMenu");55label.setOpaque(true);56final JPanel contentPane = new JPanel(new BorderLayout());57contentPane.setBorder(BorderFactory.createLineBorder(Color.RED));58window.setContentPane(contentPane);59contentPane.add(label, BorderLayout.NORTH);6061final JComboBox comboBox = new JComboBox(new Object[]{"1", "2", "3", "4"});62contentPane.add(comboBox, BorderLayout.SOUTH);6364final JPopupMenu jPopupMenu = new JPopupMenu();6566jPopupMenu.add("string");67jPopupMenu.add(new AbstractAction("action") {68@Override69public void actionPerformed(final ActionEvent e) {70}71});72jPopupMenu.add(new JLabel("label"));73jPopupMenu.add(new JMenuItem("MenuItem"));74label.addMouseListener(new MouseAdapter() {75@Override76public void mouseReleased(final MouseEvent e) {77jPopupMenu.show(label, 0, 0);78}79});8081window.setBackground(new Color(0, 0, 0, 0));8283window.setVisible(true);84});85}86}878889