Skip to content

Commit 6c4a327

Browse files
author
Satyen Subramaniam
committed
8353958: Open source several AWT ScrollPane tests - Batch 2
Backport-of: e00355a036936c5290cf8d85fd3c4f743b0ad23a
1 parent 0a31d7a commit 6c4a327

File tree

6 files changed

+517
-0
lines changed

6 files changed

+517
-0
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ java/awt/FileDialog/ModalFocus/FileDialogModalFocusTest.java 8194751 linux-all
460460
java/awt/image/VolatileImage/BitmaskVolatileImage.java 8133102 linux-all
461461
java/awt/SplashScreen/MultiResolutionSplash/unix/UnixMultiResolutionSplashTest.java 8203004 linux-all
462462
java/awt/ScrollPane/ScrollPositionTest.java 8040070 linux-all
463+
java/awt/ScrollPane/ScrollPaneScrollType/ScrollPaneEventType.java 8296516 macosx-all
463464
java/awt/Robot/AcceptExtraMouseButtons/AcceptExtraMouseButtons.java 7107528 linux-all,macosx-all
464465
java/awt/Mouse/MouseDragEvent/MouseDraggedTest.java 8080676 linux-all
465466
java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersInKeyEvent.java 8157147 linux-all,windows-all,macosx-all
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 4152524
27+
* @summary ScrollPane AS_NEEDED always places scrollbars first time component
28+
* is laid out
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual ScrollPaneAsNeededTest
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import java.awt.Button;
36+
import java.awt.Frame;
37+
import java.awt.ScrollPane;
38+
39+
public class ScrollPaneAsNeededTest {
40+
public static void main(String[] args) throws Exception {
41+
String INSTRUCTIONS = """
42+
1. You will see a frame titled 'ScrollPane as needed'
43+
of minimum possible size in the middle of the screen.
44+
2. If for the first resize of frame(using mouse) to
45+
a very big size(may be, to half the area of the screen)
46+
the scrollbars(any - horizontal, vertical or both)
47+
appear, click FAIL else, click PASS.
48+
""";
49+
PassFailJFrame.builder()
50+
.title("Test Instructions")
51+
.instructions(INSTRUCTIONS)
52+
.columns(35)
53+
.testUI(ScrollPaneAsNeededTest::initialize)
54+
.build()
55+
.awaitAndCheck();
56+
}
57+
58+
static Frame initialize() {
59+
Frame f = new Frame("ScrollPane as needed");
60+
f.setLayout(new BorderLayout());
61+
ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
62+
sp.add(new Button("TEST"));
63+
f.add("Center", sp);
64+
f.setSize(200, 200);
65+
return f;
66+
}
67+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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 4100671
27+
* @summary removing and adding back ScrollPane component does not work
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual ScrollPaneComponentTest
31+
*/
32+
33+
import java.awt.Adjustable;
34+
import java.awt.BorderLayout;
35+
import java.awt.Button;
36+
import java.awt.Color;
37+
import java.awt.Component;
38+
import java.awt.Dimension;
39+
import java.awt.Frame;
40+
import java.awt.Graphics;
41+
import java.awt.Panel;
42+
import java.awt.ScrollPane;
43+
import java.awt.event.ActionEvent;
44+
import java.awt.event.ActionListener;
45+
46+
public class ScrollPaneComponentTest {
47+
public static void main(String[] args) throws Exception {
48+
String INSTRUCTIONS = """
49+
1. Notice the scrollbars (horizontal and vertical)
50+
in the Frame titled 'ScrollPane Component Test'
51+
2. Click the button labeled 'Remove and add back
52+
ScrollPane Contents'
53+
3. If the Scrollbars (horizontal or vertical or both)
54+
disappears in the Frame, then press FAIL, else press PASS.
55+
""";
56+
PassFailJFrame.builder()
57+
.title("Test Instructions")
58+
.instructions(INSTRUCTIONS)
59+
.columns(35)
60+
.testUI(ScrollPaneComponentTest::initialize)
61+
.build()
62+
.awaitAndCheck();
63+
}
64+
65+
static Frame initialize() {
66+
Frame fr = new Frame("ScrollPane Component Test");
67+
fr.setLayout(new BorderLayout());
68+
ScrollTester test = new ScrollTester();
69+
70+
fr.add(test);
71+
fr.pack();
72+
fr.setSize(200, 200);
73+
74+
Adjustable vadj = test.pane.getVAdjustable();
75+
Adjustable hadj = test.pane.getHAdjustable();
76+
vadj.setUnitIncrement(5);
77+
hadj.setUnitIncrement(5);
78+
return fr;
79+
}
80+
}
81+
82+
class Box extends Component {
83+
public Dimension getPreferredSize() {
84+
System.out.println("asked for size");
85+
return new Dimension(300, 300);
86+
}
87+
88+
public void paint(Graphics gr) {
89+
super.paint(gr);
90+
gr.setColor(Color.red);
91+
gr.drawLine(5, 5, 295, 5);
92+
gr.drawLine(295, 5, 295, 295);
93+
gr.drawLine(295, 295, 5, 295);
94+
gr.drawLine(5, 295, 5, 5);
95+
System.out.println("Painted!!");
96+
}
97+
}
98+
99+
class ScrollTester extends Panel {
100+
public ScrollPane pane;
101+
private final Box child;
102+
103+
class Handler implements ActionListener {
104+
public void actionPerformed(ActionEvent e) {
105+
System.out.println("Removing scrollable component");
106+
pane.remove(child);
107+
System.out.println("Adding back scrollable component");
108+
pane.add(child);
109+
System.out.println("Done Adding back scrollable component");
110+
}
111+
}
112+
113+
public ScrollTester() {
114+
pane = new ScrollPane();
115+
pane.setSize(200, 200);
116+
child = new Box();
117+
pane.add(child);
118+
setLayout(new BorderLayout());
119+
Button changeScrollContents = new Button("Remove and add back ScrollPane Contents");
120+
changeScrollContents.setBackground(Color.red);
121+
changeScrollContents.addActionListener(new Handler());
122+
add("North", changeScrollContents);
123+
add("Center", pane);
124+
}
125+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 4075484
27+
* @summary Tests that events of different types are generated for the
28+
* corresponding scroll actions.
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual ScrollPaneEventType
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import java.awt.Button;
36+
import java.awt.Dimension;
37+
import java.awt.Frame;
38+
import java.awt.ScrollPane;
39+
import java.awt.event.AdjustmentListener;
40+
41+
public class ScrollPaneEventType {
42+
public static void main(String[] args) throws Exception {
43+
String INSTRUCTIONS = """
44+
1. This test verifies that when user performs some scrolling operation on
45+
ScrollPane the correct AdjustmentEvent is being generated.
46+
2. To test this, press on:
47+
- scrollbar's arrows and verify that UNIT event is generated,
48+
- scrollbar's grey area(non-thumb) and verify that BLOCK event is
49+
generated,
50+
- drag scrollbar's thumb and verify that TRACK event is generated
51+
If you see correct events for both scroll bars then test is PASSED.
52+
Otherwise it is FAILED.
53+
""";
54+
PassFailJFrame.builder()
55+
.title("Test Instructions")
56+
.instructions(INSTRUCTIONS)
57+
.columns(35)
58+
.testUI(ScrollPaneEventType::initialize)
59+
.logArea()
60+
.build()
61+
.awaitAndCheck();
62+
}
63+
64+
static Frame initialize() {
65+
Frame frame = new Frame("ScrollPane event type test");
66+
frame.setLayout(new BorderLayout());
67+
ScrollPane pane = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
68+
pane.add(new Button("press") {
69+
public Dimension getPreferredSize() {
70+
return new Dimension(1000, 1000);
71+
}
72+
});
73+
74+
AdjustmentListener listener = e -> PassFailJFrame.log(e.toString());
75+
pane.getHAdjustable().addAdjustmentListener(listener);
76+
pane.getVAdjustable().addAdjustmentListener(listener);
77+
frame.add(pane);
78+
frame.setSize(200, 200);
79+
return frame;
80+
}
81+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 4117404
27+
* @summary Tests that child component is always at least large as scrollpane
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual ScrollPaneSize
31+
*/
32+
33+
import java.awt.Button;
34+
import java.awt.Color;
35+
import java.awt.Dimension;
36+
import java.awt.FlowLayout;
37+
import java.awt.Frame;
38+
import java.awt.GridLayout;
39+
import java.awt.Insets;
40+
import java.awt.Panel;
41+
import java.awt.ScrollPane;
42+
import java.util.List;
43+
44+
public class ScrollPaneSize {
45+
public static void main(String[] args) throws Exception {
46+
String INSTRUCTIONS = """
47+
1. Three frames representing the three different ScrollPane scrollbar
48+
policies will appear.
49+
2. Verify that when you resize the windows, the child component in the
50+
scrollpane always expands to fill the scrollpane. The scrollpane
51+
background is colored red to show any improper bleed through.
52+
""";
53+
PassFailJFrame.builder()
54+
.title("Test Instructions")
55+
.instructions(INSTRUCTIONS)
56+
.columns(40)
57+
.testUI(ScrollPaneSize::initialize)
58+
.positionTestUIRightColumn()
59+
.build()
60+
.awaitAndCheck();
61+
}
62+
63+
static List<Frame> initialize() {
64+
return List.of(new ScrollFrame("SCROLLBARS_AS_NEEDED", ScrollPane.SCROLLBARS_AS_NEEDED),
65+
new ScrollFrame("SCROLLBARS_ALWAYS", ScrollPane.SCROLLBARS_ALWAYS),
66+
new ScrollFrame("SCROLLBARS_NEVER", ScrollPane.SCROLLBARS_NEVER));
67+
}
68+
}
69+
70+
class ScrollFrame extends Frame {
71+
ScrollFrame(String title, int policy) {
72+
super(title);
73+
setLayout(new GridLayout(1, 1));
74+
ScrollPane c = new ScrollPane(policy);
75+
c.setBackground(Color.red);
76+
Panel panel = new TestPanel();
77+
c.add(panel);
78+
add(c);
79+
pack();
80+
Dimension size = panel.getPreferredSize();
81+
Insets insets = getInsets();
82+
setSize(size.width + 45 + insets.right + insets.left,
83+
size.height + 20 + insets.top + insets.bottom);
84+
}
85+
}
86+
87+
class TestPanel extends Panel {
88+
TestPanel() {
89+
setLayout(new FlowLayout());
90+
setBackground(Color.white);
91+
92+
Button b1, b2, b3;
93+
add(b1 = new Button("Button1"));
94+
add(b2 = new Button("Button2"));
95+
add(b3 = new Button("Button3"));
96+
}
97+
}

0 commit comments

Comments
 (0)