Skip to content

Commit d1d7d25

Browse files
author
Tejesh R
committed
8353957: Open source several AWT ScrollPane tests - Batch 1
Reviewed-by: psadhukhan
1 parent e2cb646 commit d1d7d25

File tree

5 files changed

+520
-0
lines changed

5 files changed

+520
-0
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ java/awt/Focus/TranserFocusToWindow/TranserFocusToWindow.java 6848810 macosx-all
443443
java/awt/FileDialog/ModalFocus/FileDialogModalFocusTest.java 8194751 linux-all
444444
java/awt/image/VolatileImage/BitmaskVolatileImage.java 8133102 linux-all
445445
java/awt/SplashScreen/MultiResolutionSplash/unix/UnixMultiResolutionSplashTest.java 8203004 linux-all
446+
java/awt/ScrollPane/ScrollPositionTest.java 8040070 linux-all
446447
java/awt/ScrollPane/ScrollPaneScrollType/ScrollPaneEventType.java 8296516 macosx-all
447448
java/awt/Robot/AcceptExtraMouseButtons/AcceptExtraMouseButtons.java 7107528 linux-all,macosx-all
448449
java/awt/Mouse/MouseDragEvent/MouseDraggedTest.java 8080676 linux-all
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
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 4073822
27+
* @summary ScrollPane repaints entire window when scrolling fast
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual ScrollPaneFlicker
31+
*/
32+
33+
import java.awt.Button;
34+
import java.awt.Canvas;
35+
import java.awt.Checkbox;
36+
import java.awt.Choice;
37+
import java.awt.Color;
38+
import java.awt.Component;
39+
import java.awt.Dimension;
40+
import java.awt.Font;
41+
import java.awt.Frame;
42+
import java.awt.Graphics;
43+
import java.awt.Label;
44+
import java.awt.Menu;
45+
import java.awt.MenuBar;
46+
import java.awt.MenuItem;
47+
import java.awt.Panel;
48+
import java.awt.Rectangle;
49+
import java.awt.ScrollPane;
50+
import java.awt.Scrollbar;
51+
import java.awt.TextArea;
52+
import java.awt.TextField;
53+
import javax.swing.JButton;
54+
import javax.swing.JCheckBox;
55+
import javax.swing.JComboBox;
56+
import javax.swing.JLabel;
57+
import javax.swing.JList;
58+
import javax.swing.JPanel;
59+
import javax.swing.JScrollBar;
60+
import javax.swing.JTextArea;
61+
import javax.swing.JTextField;
62+
63+
public class ScrollPaneFlicker {
64+
public static void main(String[] args) throws Exception {
65+
String INSTRUCTIONS = """
66+
When scrolling a ScrollPane fast(i.e. holding the down/up arrow
67+
down for a while), the ScrollPane would inexplicably refresh
68+
the entire window.
69+
70+
1. Select a type of ScrollPane content from the content menu.
71+
2. Scroll the content using the up/down/left/right arrows on
72+
the scroll bar. Try scrolling the entire content area using
73+
the scroll arrows-- from top to bottom and left to right.
74+
3. Verify that the entire pane does not refresh when scrolling
75+
- only the newly exposed areas should be repainting.
76+
4. Repeat for all content types.
77+
""";
78+
PassFailJFrame.builder()
79+
.title("Test Instructions")
80+
.instructions(INSTRUCTIONS)
81+
.columns(35)
82+
.testUI(ScrollPaneFlicker::initialize)
83+
.build()
84+
.awaitAndCheck();
85+
}
86+
87+
static Frame initialize() {
88+
return new FlickerFrame();
89+
}
90+
}
91+
92+
class FlickerFrame extends Frame {
93+
ScrollPane pane;
94+
95+
public FlickerFrame() {
96+
super("ScrollPane Flicker Test");
97+
TextPanel textPanel = new TextPanel();
98+
GradientPanel gradientPanel = new GradientPanel();
99+
ComponentPanel componentPanel = new ComponentPanel();
100+
SwingPanel swingPanel = new SwingPanel();
101+
MenuBar menubar = new MenuBar();
102+
Menu testMenu = new Menu("Test Options");
103+
104+
pane = new ScrollPane();
105+
pane.getHAdjustable().setUnitIncrement(8);
106+
pane.getVAdjustable().setUnitIncrement(16);
107+
pane.add(textPanel);
108+
add(pane);
109+
110+
testMenu.add(makeContentItem("Text Lines", textPanel));
111+
testMenu.add(makeContentItem("Gradient Fill", gradientPanel));
112+
testMenu.add(makeContentItem("AWT Components", componentPanel));
113+
testMenu.add(makeContentItem("Swing Components", swingPanel));
114+
menubar.add(testMenu);
115+
116+
setMenuBar(menubar);
117+
setSize(400, 300);
118+
}
119+
120+
public MenuItem makeContentItem(String title, final Component content) {
121+
MenuItem menuItem = new MenuItem(title);
122+
menuItem.addActionListener(
123+
ev -> {
124+
pane.add(content);
125+
pane.validate();
126+
}
127+
);
128+
return menuItem;
129+
}
130+
}
131+
132+
class GradientPanel extends Canvas {
133+
public void paint(Graphics g) {
134+
// just paint something that'll take a while
135+
int x, y;
136+
int width = getSize().width;
137+
int height = getSize().height;
138+
int step = 8;
139+
140+
for (x = 0; x < width; x += step) {
141+
for (y = 0; y < height; y += step) {
142+
int red = (255 * y) / height;
143+
int green = (255 * x * y) / (width * height);
144+
int blue = (255 * x) / width;
145+
Rectangle bounds = g.getClipBounds();
146+
Rectangle fbounds = new Rectangle(x, y, x + step, y + step);
147+
if (bounds.intersects(fbounds)) {
148+
Color color = new Color(red, green, blue);
149+
g.setColor(color);
150+
g.fillRect(x, y, x + step, y + step);
151+
}
152+
}
153+
}
154+
}
155+
156+
public Dimension getPreferredSize() {
157+
return new Dimension(200, 1000);
158+
}
159+
}
160+
161+
class TextPanel extends Canvas {
162+
public void paint(Graphics g) {
163+
Font font = new Font("SanSerif", Font.ITALIC, 12);
164+
165+
g.setFont(font);
166+
// just paint something that'll take a while
167+
int x, y;
168+
int width = getWidth();
169+
int height = getHeight();
170+
int step = 16;
171+
172+
for (x = y = 0; y < height; y += step) {
173+
Rectangle bounds = g.getClipBounds();
174+
Rectangle tbounds = new Rectangle(x, y - 16, x + width, y);
175+
if (bounds.intersects(tbounds)) {
176+
g.drawString(y + " : The quick brown fox jumps over the lazy dog. " +
177+
"The rain in Spain falls mainly on the plain.", x, y);
178+
}
179+
}
180+
}
181+
182+
public Dimension getPreferredSize() {
183+
return new Dimension(640, 1000);
184+
}
185+
}
186+
187+
class ComponentPanel extends Panel {
188+
ComponentPanel() {
189+
add(new Label("Label"));
190+
add(new Button("Button"));
191+
add(new Checkbox("Checkbox"));
192+
Choice c = new Choice();
193+
c.add("choice");
194+
java.awt.List l = new java.awt.List();
195+
l.add("list");
196+
add(new Scrollbar());
197+
add(new TextField("TextField"));
198+
add(new TextArea("TextArea"));
199+
add(new Panel());
200+
add(new Canvas());
201+
}
202+
}
203+
204+
class SwingPanel extends JPanel {
205+
SwingPanel() {
206+
add(new JLabel("JLabel"));
207+
add(new JButton("JButton"));
208+
add(new JCheckBox("JCheckBox"));
209+
JComboBox c = new JComboBox();
210+
JList l = new JList();
211+
add(new JScrollBar());
212+
add(new JTextField("This is a JTextField with some text in it to make it longer."));
213+
add(new JTextArea("This is a JTextArea with some text in it to make it longer."));
214+
}
215+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
* Licensed Materials - Property of IBM
26+
*
27+
* (C) Copyright IBM Corporation 1998 All Rights Reserved.
28+
*
29+
* US Government Users Restricted Rights - Use, duplication or disclosure
30+
* restricted by GSA ADP Schedule Contract with IBM Corp.
31+
*/
32+
33+
/*
34+
* @test
35+
* @bug 4160721
36+
* @summary AWT ScrollPane painting problem
37+
* @library /java/awt/regtesthelpers
38+
* @build PassFailJFrame
39+
* @run main/manual ScrollPanePaint
40+
*/
41+
42+
import java.awt.BorderLayout;
43+
import java.awt.Button;
44+
import java.awt.Color;
45+
import java.awt.Container;
46+
import java.awt.Dimension;
47+
import java.awt.Frame;
48+
import java.awt.GridLayout;
49+
import java.awt.Panel;
50+
import java.awt.ScrollPane;
51+
import java.awt.event.ActionEvent;
52+
import java.awt.event.ActionListener;
53+
import java.util.List;
54+
55+
public class ScrollPanePaint {
56+
public static void main(String[] args) throws Exception {
57+
String INSTRUCTIONS = """
58+
1. Press the button marked "Toggle" a few times.
59+
2. The contents of the frame should alternate between
60+
a red panel and a scroll pane containing a green panel.
61+
If this does not happen (specifically, if the scroll
62+
pane does not consistently contain a green panel),
63+
then the test has FAILED.
64+
""";
65+
ScrollPaintTest scrollPaintTest = new ScrollPaintTest();
66+
PassFailJFrame.builder()
67+
.title("Test Instructions")
68+
.instructions(INSTRUCTIONS)
69+
.columns(35)
70+
.testUI(scrollPaintTest::initialize)
71+
.positionTestUI(WindowLayouts::rightOneColumn)
72+
.build()
73+
.awaitAndCheck();
74+
}
75+
76+
private static class ScrollPaintTest implements ActionListener {
77+
static Frame f;
78+
static boolean showScroll;
79+
80+
public List<Frame> initialize() {
81+
Frame frame = new Frame("Scrollpane paint test");
82+
frame.setLayout(new BorderLayout());
83+
f = new Frame("Scrollpane paint test");
84+
f.setLayout(new GridLayout(0, 1));
85+
86+
Button b = new Button("Toggle");
87+
b.addActionListener(this);
88+
89+
frame.add(b, BorderLayout.CENTER);
90+
frame.pack();
91+
92+
showScroll = false;
93+
actionPerformed(null);
94+
return List.of(frame, f);
95+
}
96+
97+
public void actionPerformed(ActionEvent e) {
98+
Container c;
99+
if (!showScroll) {
100+
c = (Container) new TestPanel(new Dimension(100, 100));
101+
c.setBackground(Color.red);
102+
} else {
103+
c = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
104+
Panel p = new TestPanel(new Dimension(20, 20));
105+
p.setBackground(Color.green);
106+
c.add(p);
107+
}
108+
109+
f.removeAll();
110+
f.add("Center", c);
111+
f.pack();
112+
showScroll = !showScroll;
113+
}
114+
}
115+
116+
private static class TestPanel extends Panel {
117+
Dimension dim;
118+
119+
TestPanel(Dimension d) {
120+
dim = d;
121+
}
122+
123+
public Dimension getMinimumSize() {
124+
return getPreferredSize();
125+
}
126+
127+
public Dimension getPreferredSize() {
128+
return dim;
129+
}
130+
}
131+
132+
}

0 commit comments

Comments
 (0)