Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JPopupMenu/7160604/bug7160604.java
41155 views
1
/*
2
* Copyright (c) 2013, 2014, 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
/* @test
25
@bug 7160604
26
@summary Using non-opaque windows - popups are initially not painted correctly
27
@author Oleg Pekhovskiy
28
@run applet/manual=yesno bug7160604.html
29
*/
30
31
import javax.swing.AbstractAction;
32
import javax.swing.BorderFactory;
33
import javax.swing.JApplet;
34
import javax.swing.JComboBox;
35
import javax.swing.JLabel;
36
import javax.swing.JMenuItem;
37
import javax.swing.JPanel;
38
import javax.swing.JPopupMenu;
39
import javax.swing.JWindow;
40
import javax.swing.SwingUtilities;
41
import java.awt.*;
42
import java.awt.event.ActionEvent;
43
import java.awt.event.MouseAdapter;
44
import java.awt.event.MouseEvent;
45
import static java.awt.GraphicsDevice.WindowTranslucency.*;
46
47
public class bug7160604 extends JApplet {
48
49
public void init() {
50
SwingUtilities.invokeLater(() -> {
51
if (!GraphicsEnvironment
52
.getLocalGraphicsEnvironment()
53
.getDefaultScreenDevice()
54
.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT)) {
55
// Tested translucency is not supported. Test passed
56
return;
57
}
58
59
final JWindow window = new JWindow();
60
window.setLocation(200, 200);
61
window.setSize(300, 300);
62
63
final JLabel label = new JLabel("...click to invoke JPopupMenu");
64
label.setOpaque(true);
65
final JPanel contentPane = new JPanel(new BorderLayout());
66
contentPane.setBorder(BorderFactory.createLineBorder(Color.RED));
67
window.setContentPane(contentPane);
68
contentPane.add(label, BorderLayout.NORTH);
69
70
final JComboBox comboBox = new JComboBox(new Object[]{"1", "2", "3", "4"});
71
contentPane.add(comboBox, BorderLayout.SOUTH);
72
73
final JPopupMenu jPopupMenu = new JPopupMenu();
74
75
jPopupMenu.add("string");
76
jPopupMenu.add(new AbstractAction("action") {
77
@Override
78
public void actionPerformed(final ActionEvent e) {
79
}
80
});
81
jPopupMenu.add(new JLabel("label"));
82
jPopupMenu.add(new JMenuItem("MenuItem"));
83
label.addMouseListener(new MouseAdapter() {
84
@Override
85
public void mouseReleased(final MouseEvent e) {
86
jPopupMenu.show(label, 0, 0);
87
}
88
});
89
90
window.setBackground(new Color(0, 0, 0, 0));
91
92
window.setVisible(true);
93
});
94
}
95
}
96
97