Skip to content

Commit e151ba4

Browse files
committed
8353475: Open source two Swing DefaultCaret tests
Backport-of: e08441c03352543f800aef166afabec1dacaf4bf
1 parent 716b87f commit e151ba4

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 4193062
27+
* @summary Tests that when a TextField first gets focus, if modelToView fails
28+
* (null is returned) that the caret will start to blink again.
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual PaintTest
32+
*/
33+
34+
import java.awt.FlowLayout;
35+
import javax.swing.JFrame;
36+
import javax.swing.JTextField;
37+
38+
public class PaintTest {
39+
40+
static final String INSTRUCTIONS = """
41+
If the test window displays with the text caret flashing (do wait at
42+
least several second for it to start) the test PASSES, otherwise it FAILS.
43+
""";
44+
45+
public static void main(String[] args) throws Exception {
46+
PassFailJFrame.builder()
47+
.title("PaintTest Test Instructions")
48+
.instructions(INSTRUCTIONS)
49+
.columns(50)
50+
.testUI(PaintTest::createUI)
51+
.build()
52+
.awaitAndCheck();
53+
}
54+
55+
static JFrame createUI() {
56+
JFrame frame = new JFrame("PaintTest");
57+
JTextField tf = new JTextField(20);
58+
frame.setLayout(new FlowLayout());
59+
frame.add(tf);
60+
frame.setSize(300, 300);
61+
return frame;
62+
}
63+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2003, 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 4785160
27+
* @summary Test that the cursor is always visible when typing in JTextArea with JScrollBar
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4785160
31+
*/
32+
33+
import javax.swing.JFrame;
34+
import javax.swing.JScrollPane;
35+
import javax.swing.JTextArea;
36+
37+
public class bug4785160 {
38+
39+
static final String INSTRUCTIONS = """
40+
Ensure that the horizontal scrollbar is visible in the JTextArea.
41+
If necessary, reduce the width of the window so that the scrollbar becomes visible.
42+
Scroll all the way to the right so the end of the line is visible.
43+
If necessary, move the text caret in the text area to the end of line.
44+
The test PASSES if the caret is visible at the end of the line.
45+
The test FAILS if the caret disappears when moved to the end of the line.
46+
""";
47+
48+
public static void main(String[] args) throws Exception {
49+
PassFailJFrame.builder()
50+
.title("bug4785160 Test Instructions")
51+
.instructions(INSTRUCTIONS)
52+
.columns(50)
53+
.testUI(bug4785160::createUI)
54+
.build()
55+
.awaitAndCheck();
56+
}
57+
58+
static JFrame createUI() {
59+
JFrame frame = new JFrame("bug4785160");
60+
JTextArea area = new JTextArea();
61+
String s = "";
62+
for (int i = 0; i < 80; i++) {
63+
s += "m";
64+
}
65+
area.setText(s);
66+
area.getCaret().setDot(area.getText().length() + 1);
67+
frame.add(new JScrollPane(area));
68+
frame.setSize(300, 300);
69+
return frame;
70+
}
71+
}

0 commit comments

Comments
 (0)