Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JLabel/7004134/bug7004134.java
41153 views
1
/*
2
* Copyright (c) 2010, 2015, 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 7004134
28
* @summary JLabel containing a ToolTipText does no longer show ToolTip after browser refresh
29
* @author Pavel Porvatov
30
* @modules java.desktop/sun.awt
31
* @modules java.desktop/javax.swing:open
32
*/
33
34
import sun.awt.SunToolkit;
35
36
import javax.swing.*;
37
import java.awt.*;
38
import java.awt.event.MouseEvent;
39
import java.lang.reflect.Field;
40
41
public class bug7004134 {
42
private static volatile JFrame frame;
43
44
private static volatile JLabel label;
45
46
private static volatile int toolTipWidth;
47
48
public static void main(String[] args) throws Exception {
49
SwingUtilities.invokeAndWait(new Runnable() {
50
public void run() {
51
label = new JLabel("A JLabel used as object for an HTML-formatted tooltip");
52
label.setToolTipText("<html><body bgcolor=FFFFE1>An HTML-formatted ToolTip</body></html>");
53
54
frame = new JFrame();
55
56
frame.add(label);
57
frame.pack();
58
frame.setVisible(true);
59
}
60
});
61
62
((SunToolkit) SunToolkit.getDefaultToolkit()).realSync();
63
64
SwingUtilities.invokeAndWait(new Runnable() {
65
public void run() {
66
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
67
68
toolTipManager.setInitialDelay(0);
69
toolTipManager.mouseMoved(new MouseEvent(label, 0, 0, 0, 0, 0, 0, false));
70
}
71
});
72
73
Thread.sleep(500);
74
75
SwingUtilities.invokeAndWait(new Runnable() {
76
public void run() {
77
toolTipWidth = getTipWindow().getWidth();
78
79
frame.dispose();
80
}
81
});
82
83
Thread thread = new Thread(new ThreadGroup("Some ThreadGroup"), new Runnable() {
84
public void run() {
85
SunToolkit.createNewAppContext();
86
87
try {
88
SwingUtilities.invokeAndWait(new Runnable() {
89
public void run() {
90
frame = new JFrame();
91
92
frame.add(label);
93
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
94
frame.pack();
95
frame.setVisible(true);
96
}
97
});
98
99
((SunToolkit) SunToolkit.getDefaultToolkit()).realSync();
100
101
SwingUtilities.invokeAndWait(new Runnable() {
102
public void run() {
103
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
104
105
toolTipManager.setInitialDelay(0);
106
toolTipManager.mouseMoved(new MouseEvent(label, 0, 0, 0, 0, 0, 0, false));
107
}
108
});
109
110
Thread.sleep(500);
111
112
SwingUtilities.invokeAndWait(new Runnable() {
113
public void run() {
114
int newToolTipWidth = getTipWindow().getWidth();
115
116
frame.dispose();
117
118
if (toolTipWidth != newToolTipWidth) {
119
throw new RuntimeException("Tooltip width is different. Initial: " + toolTipWidth +
120
", new: " + newToolTipWidth);
121
}
122
}
123
});
124
} catch (Exception e) {
125
throw new RuntimeException(e);
126
}
127
128
}
129
});
130
131
thread.start();
132
thread.join();
133
}
134
135
private static Component getTipWindow() {
136
try {
137
Field tipWindowField = ToolTipManager.class.getDeclaredField("tipWindow");
138
139
tipWindowField.setAccessible(true);
140
141
Popup value = (Popup) tipWindowField.get(ToolTipManager.sharedInstance());
142
143
Field componentField = Popup.class.getDeclaredField("component");
144
145
componentField.setAccessible(true);
146
147
return (Component) componentField.get(value);
148
} catch (Exception e) {
149
throw new RuntimeException("getToolTipComponent failed", e);
150
}
151
}
152
}
153
154