Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk21 Public archive

Commit 480dc22

Browse files
committed
8311689: Wrong visible amount in Adjustable of ScrollPane
Reviewed-by: honkar, azvegint, prr Backport-of: b3f34039fedd3c49404783ec880e1885dceb296b
1 parent 308b4c6 commit 480dc22

File tree

2 files changed

+97
-2
lines changed

2 files changed

+97
-2
lines changed

src/java.desktop/windows/native/libawt/windows/awt_ScrollPane.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,8 @@ void AwtScrollPane::_SetSpans(void *param)
524524
DTRACE_PRINTLN5("%x: WScrollPanePeer.setSpans(%d, %d, %d, %d)", self,
525525
parentWidth, parentHeight, childWidth, childHeight);
526526
s->RecalcSizes(parentWidth, parentHeight, childWidth, childHeight);
527-
s->VerifyState();
528527
s->SetInsets(env);
528+
s->VerifyState();
529529
}
530530
ret:
531531
env->DeleteGlobalRef(self);
@@ -804,7 +804,7 @@ Java_sun_awt_windows_WScrollPanePeer_setSpans(JNIEnv *env, jobject self,
804804
sss->childWidth = childWidth;
805805
sss->childHeight = childHeight;
806806

807-
AwtToolkit::GetInstance().InvokeFunctionLater(AwtScrollPane::_SetSpans, sss);
807+
AwtToolkit::GetInstance().InvokeFunction(AwtScrollPane::_SetSpans, sss);
808808
// global ref and sss are deleted in _SetSpans
809809

810810
CATCH_BAD_ALLOC;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) 2023, 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+
import java.awt.Canvas;
25+
import java.awt.Color;
26+
import java.awt.Dimension;
27+
import java.awt.Frame;
28+
import java.awt.Graphics;
29+
import java.awt.Point;
30+
import java.awt.Robot;
31+
import java.awt.ScrollPane;
32+
33+
/*
34+
* @test
35+
* @bug 8311689
36+
* @key headful
37+
* @requires os.family=="windows"
38+
* @summary Verifies ScrollPane allows viewing the whole contents of its child
39+
* @run main ScrollPaneScrollEnd
40+
*/
41+
public final class ScrollPaneScrollEnd {
42+
private static final Color CANVAS_BACKGROUND = new Color(255, 200, 200);
43+
private static final Color CANVAS_FOREGROUND = new Color(255, 255, 200);
44+
private static final int OFFSET = 12;
45+
46+
private static final Dimension CANVAS_SIZE = new Dimension(900, 600);
47+
private static final Dimension SCROLL_PANE_SIZE =
48+
new Dimension(CANVAS_SIZE.width / 3, CANVAS_SIZE.height / 3);
49+
private static final int SCROLL_OFFSET = 100;
50+
51+
private static final int DELAY = 200;
52+
53+
public static void main(String[] args) throws Exception {
54+
Canvas canvas = new Canvas() {
55+
@Override
56+
public void paint(Graphics g) {
57+
g.setColor(CANVAS_BACKGROUND);
58+
g.fillRect(0, 0, getWidth(), getHeight());
59+
60+
g.setColor(CANVAS_FOREGROUND);
61+
g.fillRect(OFFSET, OFFSET,
62+
getWidth() - OFFSET * 2, getHeight() - OFFSET * 2);
63+
}
64+
};
65+
canvas.setSize(CANVAS_SIZE);
66+
67+
ScrollPane scrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
68+
scrollPane.add(canvas);
69+
scrollPane.setSize(SCROLL_PANE_SIZE);
70+
71+
Frame frame = new Frame("ScrollPaneScrollEnd");
72+
frame.add(scrollPane, "Center");
73+
frame.setLocation(100, 100);
74+
frame.pack();
75+
frame.setVisible(true);
76+
77+
final Robot robot = new Robot();
78+
robot.waitForIdle();
79+
robot.delay(DELAY);
80+
81+
final Dimension vp = scrollPane.getViewportSize();
82+
final Point expected = new Point(CANVAS_SIZE.width - vp.width,
83+
CANVAS_SIZE.height - vp.height);
84+
85+
scrollPane.setScrollPosition(CANVAS_SIZE.width + SCROLL_OFFSET,
86+
CANVAS_SIZE.height + SCROLL_OFFSET);
87+
try {
88+
if (!expected.equals(scrollPane.getScrollPosition())) {
89+
throw new Error("Can't scroll to the end of the child component");
90+
}
91+
} finally {
92+
frame.dispose();
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)