|
| 1 | +/* |
| 2 | + * Copyright (c) 2013, 2024, 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 7160604 |
| 27 | + * @summary Using non-opaque windows - popups are initially not painted correctly |
| 28 | + * @library /java/awt/regtesthelpers |
| 29 | + * @build PassFailJFrame |
| 30 | + * @run main/manual bug7160604 |
| 31 | +*/ |
| 32 | +import java.awt.BorderLayout; |
| 33 | +import java.awt.Color; |
| 34 | +import java.awt.GraphicsEnvironment; |
| 35 | +import java.awt.event.ActionEvent; |
| 36 | +import java.awt.event.MouseAdapter; |
| 37 | +import java.awt.event.MouseEvent; |
| 38 | +import static java.awt.GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSLUCENT; |
| 39 | +import javax.swing.AbstractAction; |
| 40 | +import javax.swing.BorderFactory; |
| 41 | +import javax.swing.JComboBox; |
| 42 | +import javax.swing.JLabel; |
| 43 | +import javax.swing.JMenuItem; |
| 44 | +import javax.swing.JPanel; |
| 45 | +import javax.swing.JPopupMenu; |
| 46 | +import javax.swing.JWindow; |
| 47 | +import javax.swing.SwingUtilities; |
| 48 | + |
| 49 | +public class bug7160604 { |
| 50 | + |
| 51 | + private static final String INSTRUCTIONS = """ |
| 52 | + Click on the top-bar and combo-box at the bottom more than once. |
| 53 | + Check top-bar popup menu and combo-box drop-down list have a border |
| 54 | + and their items are drawn properly. |
| 55 | + If yes, Click Pass else click Fail."""; |
| 56 | + |
| 57 | + public static void main(String[] args) throws Exception { |
| 58 | + if (!GraphicsEnvironment |
| 59 | + .getLocalGraphicsEnvironment() |
| 60 | + .getDefaultScreenDevice() |
| 61 | + .isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT)) { |
| 62 | + // Tested translucency is not supported. Test passed |
| 63 | + return; |
| 64 | + } |
| 65 | + PassFailJFrame.builder() |
| 66 | + .title("PopupMenu Instructions") |
| 67 | + .instructions(INSTRUCTIONS) |
| 68 | + .rows(5) |
| 69 | + .columns(35) |
| 70 | + .testUI(bug7160604::createTestUI) |
| 71 | + .build() |
| 72 | + .awaitAndCheck(); |
| 73 | + } |
| 74 | + |
| 75 | + private static JWindow createTestUI() { |
| 76 | + |
| 77 | + final JWindow window = new JWindow(); |
| 78 | + window.setLocation(200, 200); |
| 79 | + window.setSize(300, 300); |
| 80 | + |
| 81 | + final JLabel label = new JLabel("...click to invoke JPopupMenu"); |
| 82 | + label.setOpaque(true); |
| 83 | + final JPanel contentPane = new JPanel(new BorderLayout()); |
| 84 | + contentPane.setBorder(BorderFactory.createLineBorder(Color.RED)); |
| 85 | + window.setContentPane(contentPane); |
| 86 | + contentPane.add(label, BorderLayout.NORTH); |
| 87 | + |
| 88 | + final JComboBox comboBox = new JComboBox(new Object[]{"1", "2", "3", "4"}); |
| 89 | + contentPane.add(comboBox, BorderLayout.SOUTH); |
| 90 | + |
| 91 | + final JPopupMenu jPopupMenu = new JPopupMenu(); |
| 92 | + |
| 93 | + jPopupMenu.add("string"); |
| 94 | + jPopupMenu.add(new AbstractAction("action") { |
| 95 | + @Override |
| 96 | + public void actionPerformed(final ActionEvent e) { |
| 97 | + } |
| 98 | + }); |
| 99 | + jPopupMenu.add(new JLabel("label")); |
| 100 | + jPopupMenu.add(new JMenuItem("MenuItem")); |
| 101 | + label.addMouseListener(new MouseAdapter() { |
| 102 | + @Override |
| 103 | + public void mouseReleased(final MouseEvent e) { |
| 104 | + jPopupMenu.show(label, 0, 0); |
| 105 | + } |
| 106 | + }); |
| 107 | + |
| 108 | + window.setBackground(new Color(0, 0, 0, 0)); |
| 109 | + |
| 110 | + return window; |
| 111 | + } |
| 112 | +} |
0 commit comments