Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/PopupFactory/6276087/NonOpaquePopupMenuTest.java
38918 views
1
/*
2
* Copyright (c) 2011, 2013, 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 6276087
27
* @author Romain Guy
28
* @summary Tests opacity of a popup menu.
29
*/
30
import java.awt.*;
31
import java.awt.event.*;
32
33
import javax.swing.*;
34
35
public class NonOpaquePopupMenuTest extends JFrame {
36
37
private static JMenu fileMenu;
38
39
public NonOpaquePopupMenuTest() {
40
getContentPane().setBackground(java.awt.Color.RED);
41
JMenuBar menuBar = new JMenuBar();
42
fileMenu = new JMenu("File");
43
JMenuItem menuItem = new JMenuItem("New");
44
menuBar.add(fileMenu);
45
setJMenuBar(menuBar);
46
47
fileMenu.add(menuItem);
48
fileMenu.getPopupMenu().setOpaque(false);
49
50
setSize(new Dimension(640, 480));
51
setVisible(true);
52
}
53
54
public static void main(String[] args) throws Throwable {
55
Robot robot = new Robot();
56
robot.setAutoDelay(250);
57
58
SwingUtilities.invokeAndWait(new Runnable() {
59
60
@Override
61
public void run() {
62
new NonOpaquePopupMenuTest();
63
}
64
});
65
66
robot.waitForIdle();
67
68
Point p = getMenuClickPoint();
69
robot.mouseMove(p.x, p.y);
70
robot.mousePress(InputEvent.BUTTON1_MASK);
71
robot.mouseRelease(InputEvent.BUTTON1_MASK);
72
73
robot.waitForIdle();
74
75
if (isParentOpaque()) {
76
throw new RuntimeException("Popup menu parent is opaque");
77
}
78
79
}
80
81
private static boolean isParentOpaque() throws Exception {
82
final boolean result[] = new boolean[1];
83
84
SwingUtilities.invokeAndWait(new Runnable() {
85
86
@Override
87
public void run() {
88
result[0] = fileMenu.getPopupMenu().getParent().isOpaque();
89
}
90
});
91
92
return result[0];
93
}
94
95
private static Point getMenuClickPoint() throws Exception {
96
final Point[] result = new Point[1];
97
98
SwingUtilities.invokeAndWait(new Runnable() {
99
100
@Override
101
public void run() {
102
Point p = fileMenu.getLocationOnScreen();
103
Dimension size = fileMenu.getSize();
104
105
result[0] = new Point(p.x + size.width / 2,
106
p.y + size.height / 2);
107
}
108
});
109
110
return result[0];
111
112
}
113
}
114
115