Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/javax/swing/JEditorPane/4492274/bug4492274.java
58462 views
1
/*
2
* Copyright (c) 2007, 2011, 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 4492274
28
* @summary Tests if JEditorPane.getPage() correctly returns anchor reference.
29
* @author Denis Sharypov
30
* @run main bug4492274
31
*/
32
33
import javax.swing.*;
34
import javax.swing.text.html.HTMLEditorKit;
35
import java.awt.*;
36
import java.io.File;
37
import java.net.URL;
38
39
public class bug4492274 {
40
41
private static URL page;
42
43
private static JEditorPane jep;
44
45
private static JFrame f;
46
47
public static void main(String args[]) throws Exception {
48
try {
49
Robot robot = new Robot();
50
SwingUtilities.invokeAndWait(new Runnable() {
51
@Override
52
public void run() {
53
createAndShowGUI();
54
}
55
});
56
57
robot.waitForIdle();
58
59
SwingUtilities.invokeAndWait(new Runnable() {
60
@Override
61
public void run() {
62
try {
63
page = new URL(page, "#linkname");
64
jep.setPage(page);
65
} catch (Exception e) {
66
throw new RuntimeException(e);
67
}
68
}
69
});
70
71
robot.waitForIdle();
72
73
if (getPageAnchor() == null) {
74
throw new RuntimeException("JEditorPane.getPage() returns null anchor reference");
75
}
76
} finally {
77
if (f != null) SwingUtilities.invokeAndWait(() -> f.dispose());
78
}
79
}
80
81
private static String getPageAnchor() throws Exception {
82
final String[] result = new String[1];
83
84
SwingUtilities.invokeAndWait(new Runnable() {
85
@Override
86
public void run() {
87
result[0] = jep.getPage().getRef();
88
}
89
});
90
91
return result[0];
92
}
93
94
private static void createAndShowGUI() {
95
try {
96
File file = new File(System.getProperty("test.src", "."), "test.html");
97
page = file.toURI().toURL();
98
99
f = new JFrame();
100
101
jep = new JEditorPane();
102
jep.setEditorKit(new HTMLEditorKit());
103
jep.setEditable(false);
104
jep.setPage(page);
105
106
JScrollPane sp = new JScrollPane(jep);
107
108
f.getContentPane().add(sp);
109
f.setSize(500, 500);
110
f.setVisible(true);
111
112
} catch (Exception e) {
113
throw new RuntimeException(e);
114
}
115
}
116
}
117
118