Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JPopupMenu/4458079/bug4458079.java
41155 views
1
/*
2
* Copyright (c) 2013, 2017, 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
* @key headful
27
* @bug 4458079
28
* @library ../../regtesthelpers
29
* @build Util
30
* @summary Tests calling removeAll() from PopupMenuListener
31
* @author Peter Zhelezniakov
32
* @run main bug4458079
33
*/
34
35
import java.awt.Robot;
36
import java.awt.event.*;
37
import javax.swing.*;
38
import javax.swing.event.*;
39
import java.awt.event.KeyEvent;
40
41
public class bug4458079 extends JFrame implements PopupMenuListener {
42
public JMenu menu;
43
44
static volatile boolean itemASelected = false;
45
public static void main(String[] args) throws Exception {
46
Robot robot = new Robot();
47
robot.setAutoDelay(100);
48
// move mouse outside menu to prevent auto selection
49
robot.mouseMove(100,100);
50
robot.waitForIdle();
51
52
SwingUtilities.invokeAndWait(new Runnable() {
53
public void run() {
54
new bug4458079().createAndShowGUI();
55
}
56
});
57
58
robot.waitForIdle();
59
robot.delay(1000);
60
Util.hitMnemonics(robot, KeyEvent.VK_M);
61
62
robot.waitForIdle();
63
64
Util.hitKeys(robot, KeyEvent.VK_DOWN);
65
Util.hitKeys(robot, KeyEvent.VK_ENTER);
66
67
robot.waitForIdle();
68
69
if (!itemASelected) {
70
throw new RuntimeException("Test failed: arrow key traversal in JMenu broken!");
71
}
72
}
73
public void createAndShowGUI() {
74
JMenuBar bar = new JMenuBar();
75
menu = new JMenu("Menu");
76
menu.add(new JMenuItem("1"));
77
menu.add(new JMenuItem("2"));
78
menu.setMnemonic(KeyEvent.VK_M);
79
menu.getPopupMenu().addPopupMenuListener(this);
80
bar.add(menu);
81
82
setJMenuBar(bar);
83
getContentPane().add(new JButton(""));
84
setSize(300, 300);
85
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
86
pack();
87
setLocationRelativeTo(null);
88
setVisible(true);
89
}
90
91
public void rebuildMenu() {
92
menu.removeAll();
93
final String itemCommand = "A";
94
JMenuItem item = new JMenuItem(itemCommand);
95
item.addActionListener(new ActionListener() {
96
public void actionPerformed(ActionEvent e) {
97
JMenuItem item = ((JMenuItem)e.getSource());
98
if (e.getActionCommand() == itemCommand) {
99
itemASelected = true;
100
}
101
}
102
});
103
menu.add(item);
104
menu.add(new JMenuItem("B"));
105
}
106
107
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
108
rebuildMenu();
109
}
110
111
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
112
public void popupMenuCanceled(PopupMenuEvent e) {}
113
}
114
115