test/jdk/javax/swing/JPopupMenu/8173739/TestPopupMenu.java
author ssadetsky
Wed, 03 Apr 2019 15:43:25 -0700
branchJDK-8200758-branch
changeset 57303 eff0cf668c29
parent 47216 71c04702a3d5
permissions -rw-r--r--
8221876:[macOS] JPackage install takes long time Reviewed-by: almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47163
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
     1
/*
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
     4
 *
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
     8
 *
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    13
 * accompanied this code).
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    14
 *
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    18
 *
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    21
 * questions.
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    22
 */
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    23
/*
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    24
 * @test
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    25
 * @key headful
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    26
 * @bug 8173739
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    27
 * @summary  Verifies if JPopupMenu disappears on KeyEvent
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    28
 * @run main TestPopupMenu
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    29
 */
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    30
import java.awt.Color;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    31
import java.awt.Dimension;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    32
import java.awt.GridBagConstraints;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    33
import java.awt.GridBagLayout;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    34
import java.awt.Insets;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    35
import java.awt.Point;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    36
import java.awt.Robot;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    37
import java.awt.event.InputEvent;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    38
import java.awt.event.KeyEvent;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    39
import java.beans.PropertyVetoException;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    40
import javax.swing.JComponent;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    41
import javax.swing.JDesktopPane;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    42
import javax.swing.JFrame;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    43
import javax.swing.JInternalFrame;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    44
import javax.swing.JLabel;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    45
import javax.swing.JMenuItem;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    46
import javax.swing.JPanel;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    47
import javax.swing.JPopupMenu;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    48
import javax.swing.JScrollPane;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    49
import javax.swing.KeyStroke;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    50
import javax.swing.SwingUtilities;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    51
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    52
public class TestPopupMenu {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    53
    private JFrame frame;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    54
    private JLabel label;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    55
    private volatile Point p = null;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    56
    private volatile Dimension d = null;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    57
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    58
    public static void main(String[] args) throws Exception {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    59
        new TestPopupMenu();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    60
    }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    61
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    62
    void blockTillDisplayed(JComponent comp) throws Exception {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    63
        while (p == null) {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    64
            try {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    65
                SwingUtilities.invokeAndWait(() -> {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    66
                    p = comp.getLocationOnScreen();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    67
                    d = comp.getSize();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    68
                });
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    69
            } catch (IllegalStateException e) {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    70
                try {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    71
                    Thread.sleep(1000);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    72
                } catch (InterruptedException ie) {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    73
                }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    74
            }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    75
        }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    76
    }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    77
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    78
    public TestPopupMenu() throws Exception {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    79
        Robot robot = new Robot();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    80
        robot.setAutoDelay(200);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    81
        try {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    82
            SwingUtilities.invokeAndWait(() -> {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    83
                try {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    84
                    createAndShowUI();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    85
                } catch (Exception ex) {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    86
                    throw new RuntimeException(ex);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    87
                }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    88
            });
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    89
            blockTillDisplayed(label);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    90
            robot.waitForIdle();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    91
            robot.mouseMove(p.x + d.width/2, p.y + d.height/2);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    92
            robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    93
            robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    94
            robot.waitForIdle();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    95
            robot.keyPress(KeyEvent.VK_CONTROL);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    96
            robot.keyPress(KeyEvent.VK_U);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    97
            robot.keyRelease(KeyEvent.VK_U);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    98
            robot.keyRelease(KeyEvent.VK_CONTROL);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
    99
            robot.waitForIdle();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   100
            JPopupMenu popup = label.getComponentPopupMenu();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   101
            if (popup != null && popup.isVisible()) {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   102
                throw new RuntimeException("Popup is visible in wrong internal frame");
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   103
            }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   104
        } finally {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   105
            SwingUtilities.invokeAndWait(()->frame.dispose());
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   106
        }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   107
    }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   108
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   109
    private void createAndShowUI() throws Exception {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   110
        frame = new JFrame();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   111
        frame.setTitle("Test Frame");
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   112
        frame.setSize(800, 600);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   113
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   114
        JDesktopPane pane = new JDesktopPane();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   115
        TestInternalFrameWPopup testInternalFrame1 = new TestInternalFrameWPopup();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   116
        pane.add(testInternalFrame1);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   117
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   118
        testInternalFrame1.setVisible(true);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   119
        JScrollPane scrollPane = new JScrollPane(pane);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   120
        frame.getContentPane().add(scrollPane);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   121
        testInternalFrame1.setMaximum(true);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   122
        frame.getRootPane().registerKeyboardAction(e -> {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   123
            TestInternalFrame testInternalFrame2 = new TestInternalFrame();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   124
            pane.add(testInternalFrame2);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   125
            try {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   126
                testInternalFrame2.setMaximum(true);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   127
            } catch (PropertyVetoException ex) {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   128
                throw new RuntimeException(ex);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   129
            }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   130
            testInternalFrame2.setVisible(true);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   131
        }, KeyStroke.getKeyStroke(KeyEvent.VK_U, KeyEvent.CTRL_MASK),
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   132
                                 JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   133
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   134
        frame.setVisible(true);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   135
    }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   136
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   137
    /**
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   138
     * Background color Cyan
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   139
     */
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   140
    class TestInternalFrameWPopup extends JInternalFrame {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   141
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   142
        TestInternalFrameWPopup() {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   143
            jbInit();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   144
        }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   145
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   146
        private void jbInit() {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   147
            setTitle("Test Internal Frame With Popup");
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   148
            setContentPane(getContainerPanel());
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   149
            setMaximizable(true);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   150
            setClosable(true);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   151
            setMinimumSize(new Dimension(500, 300));
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   152
            setSize(500, 300);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   153
        }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   154
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   155
        private JPanel getContainerPanel() {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   156
            JPanel panel = new JPanel();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   157
            panel.setLayout(new GridBagLayout());
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   158
            label = new JLabel("Test Label");
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   159
            JPopupMenu popup = new JPopupMenu();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   160
            JMenuItem menuItem1 = new JMenuItem("Item 1");
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   161
            JMenuItem menuItem2 = new JMenuItem("Item 2");
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   162
            JMenuItem menuItem3 = new JMenuItem("Item 3");
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   163
            JMenuItem menuItem4 = new JMenuItem("Item 4");
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   164
            JMenuItem menuItem5 = new JMenuItem("Item 5");
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   165
            menuItem1.setOpaque(false);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   166
            menuItem2.setOpaque(false);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   167
            menuItem3.setOpaque(false);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   168
            menuItem4.setOpaque(false);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   169
            menuItem5.setOpaque(false);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   170
            popup.add(menuItem1);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   171
            popup.add(menuItem2);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   172
            popup.add(menuItem3);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   173
            popup.add(menuItem4);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   174
            popup.add(menuItem5);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   175
            label.setComponentPopupMenu(popup);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   176
            popup.setBackground(Color.CYAN);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   177
            panel.add(label, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   178
                    GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   179
            panel.setBackground(Color.CYAN);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   180
            return panel;
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   181
        }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   182
    }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   183
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   184
    /**
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   185
     * Background color Gray
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   186
     *
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   187
     */
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   188
    class TestInternalFrame extends JInternalFrame {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   189
        public TestInternalFrame() {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   190
            jbInit();
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   191
        }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   192
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   193
        private void jbInit() {
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   194
            setTitle("Test Internal Frame");
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   195
            getContentPane().setBackground(Color.GRAY);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   196
            setMaximizable(true);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   197
            setClosable(true);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   198
            setMinimumSize(new Dimension(500, 300));
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   199
            setSize(500, 300);
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   200
        }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   201
    }
6302e71a30f8 8173739: JPopupMenu does not disappear on KeyEvent
psadhukhan
parents:
diff changeset
   202
}