Skip to content

Commit a0b7f83

Browse files
author
Satyen Subramaniam
committed
8354552: Open source a few Swing tests
Backport-of: 31e293b0821b754f0fd0dd3a9d9143a0fd43a256
1 parent 52cd4fe commit a0b7f83

File tree

4 files changed

+323
-0
lines changed

4 files changed

+323
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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 4194428
27+
* @summary Checks that scrolling an href to visible scrolls it to the top of the page.
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual ScrollToReferenceTest
31+
*/
32+
33+
import java.awt.Container;
34+
import java.awt.Dimension;
35+
import java.io.IOException;
36+
import java.net.URL;
37+
import javax.swing.JEditorPane;
38+
import javax.swing.JFrame;
39+
import javax.swing.JScrollPane;
40+
import javax.swing.event.HyperlinkEvent;
41+
import javax.swing.event.HyperlinkListener;
42+
43+
public class ScrollToReferenceTest {
44+
45+
static final String INSTRUCTIONS = """
46+
Wait for the html document to finish loading, click on the anchor
47+
with text 'CLICK ME'. If 'should be at top of editor pane' is
48+
scrolled to the top of the visible region of the text, click PASS,
49+
otherwise click FAIL.
50+
""";
51+
52+
public static void main(String[] args) throws Exception {
53+
PassFailJFrame.builder()
54+
.instructions(INSTRUCTIONS)
55+
.columns(40)
56+
.testUI(ScrollToReferenceTest::createUI)
57+
.build()
58+
.awaitAndCheck();
59+
}
60+
61+
static JFrame createUI() {
62+
JFrame frame = new JFrame("ScrollToReferenceTest");
63+
JEditorPane pane = new JEditorPane();
64+
65+
try {
66+
pane.setPage(ScrollToReferenceTest.class.getResource("test.html"));
67+
} catch (IOException ioe) {
68+
PassFailJFrame.forceFail("Couldn't find html file");
69+
}
70+
71+
72+
pane.addHyperlinkListener(new HyperlinkListener() {
73+
public void hyperlinkUpdate(HyperlinkEvent e) {
74+
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED &&
75+
e.getURL() != null) {
76+
try {
77+
pane.setPage(e.getURL());
78+
} catch (IOException ioe) {
79+
pane.setText("error finding url, click fail!");
80+
}
81+
}
82+
}
83+
});
84+
pane.setEditable(false);
85+
JScrollPane sp = new JScrollPane(pane);
86+
sp.setPreferredSize(new Dimension(400, 400));
87+
frame.add(sp);
88+
frame.setSize(400, 400);
89+
return frame;
90+
}
91+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<html>
2+
<body>
3+
<p><a href="#middle">Click ME!</a>
4+
<p>a
5+
<p>a
6+
<p>a
7+
<p>a
8+
<p>a
9+
<p>a
10+
<p>a
11+
<p>a
12+
<p>a
13+
<p>a
14+
<p>a
15+
<p>a
16+
<p>a
17+
<p>a
18+
<p>a
19+
<p>a
20+
<p>a
21+
<p>a
22+
<p>a
23+
<p>a
24+
<p>a
25+
<p>a
26+
<p>a
27+
<p>a
28+
<p>a
29+
<p>a
30+
<p>a
31+
<p>a
32+
<p>a
33+
<p>a
34+
<p>a
35+
<p>a
36+
<p>a
37+
<p>a
38+
<p>a
39+
<p>a
40+
<p>a
41+
<p>a
42+
<p>a
43+
<p>a
44+
<p>a
45+
<p>a
46+
<p>a
47+
<p>a
48+
<p>a
49+
<p><a name="middle">should be at top of editor pane</a>
50+
<p>a
51+
<p>a
52+
<p>a
53+
<p>a
54+
<p>a
55+
<p>a
56+
<p>a
57+
<p>a
58+
<p>a
59+
<p>a
60+
<p>a
61+
<p>a
62+
<p>a
63+
<p>a
64+
<p>a
65+
<p>a
66+
<p>a
67+
<p>a
68+
<p>a
69+
<p>a
70+
<p>a
71+
<p>a
72+
<p>a
73+
<p>a
74+
<p>a
75+
<p>a
76+
<p>a
77+
<p>a
78+
<p>a
79+
<p>a
80+
<p>a
81+
<p>a
82+
<p>a
83+
<p>a
84+
<p>a
85+
<p>a
86+
<p>a
87+
<p>a
88+
<p>a
89+
<p>a
90+
<p><a name="test">TEST</a>!
91+
<p>a
92+
</body>
93+
</html>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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 4106007
26+
* @summary Multi-line JLabel is now supported for HTML labels.
27+
* @library /java/awt/regtesthelpers
28+
* @build PassFailJFrame
29+
* @run main/manual bug4106007
30+
* */
31+
32+
import java.awt.BorderLayout;
33+
import javax.swing.JFrame;
34+
import javax.swing.JLabel;
35+
36+
public class bug4106007 {
37+
38+
static final String INSTRUCTIONS = """
39+
The test window should have a label spanning multiple lines.
40+
If it is press PASS, else press FAIL.
41+
""";
42+
43+
public static void main(String[] args) throws Exception {
44+
PassFailJFrame.builder()
45+
.instructions(INSTRUCTIONS)
46+
.columns(40)
47+
.testUI(bug4106007::createUI)
48+
.build()
49+
.awaitAndCheck();
50+
}
51+
52+
static JFrame createUI() {
53+
JFrame frame = new JFrame("Bug4106007");
54+
frame.setLayout(new BorderLayout());
55+
String str = "<HTML><BODY>";
56+
String longLine =
57+
"I hope multi-line JLabel is now supported and you can see several lines instead of one long line. ";
58+
str += longLine;
59+
str += longLine;
60+
str += "</BODY></HTML>";
61+
JLabel lab = new JLabel(str);
62+
frame.add(lab, BorderLayout.NORTH);
63+
frame.setSize(400, 400);
64+
return frame;
65+
}
66+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2004, 2025, 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 4945795
26+
* @summary With mnemonic hiding turned on, Java does not display all mnemonics with ALT key
27+
* @requires (os.family == "windows")
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4945795
31+
* */
32+
33+
import java.awt.BorderLayout;
34+
import javax.swing.JFrame;
35+
import javax.swing.JLabel;
36+
import javax.swing.UIManager;
37+
38+
public class bug4945795 {
39+
40+
static final String INSTRUCTIONS = """
41+
This test is for the Swing Windows Look And Feel.
42+
A test window will be displayed with the label 'Mnemonic Test'
43+
Click the mouse in the test window to make sure it has keyboard focus.
44+
Now press and hold the 'Alt' key.
45+
An underline should be displayed below the initial 'M' character.
46+
If it is press PASS, else press FAIL.
47+
""";
48+
49+
public static void main(String[] args) throws Exception {
50+
PassFailJFrame.builder()
51+
.instructions(INSTRUCTIONS)
52+
.columns(40)
53+
.testUI(bug4945795::createUI)
54+
.build()
55+
.awaitAndCheck();
56+
}
57+
58+
static JFrame createUI() {
59+
JFrame mainFrame = new JFrame("Bug4945795");
60+
try {
61+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
62+
} catch (Exception ex) {
63+
throw new RuntimeException("Can not set system look and feel");
64+
}
65+
mainFrame.setLayout(new BorderLayout());
66+
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
67+
JLabel label = new JLabel("Mnemonic test");
68+
label.setDisplayedMnemonic('M');
69+
mainFrame.add(label, BorderLayout.NORTH);
70+
mainFrame.setSize(400, 300);
71+
return mainFrame;
72+
}
73+
}

0 commit comments

Comments
 (0)