Skip to content

Commit cf55984

Browse files
author
Andy Goryachev
committedOct 11, 2024
8341440: ScrollPane: no immediate effect changing fitWidth/fitHeight
Reviewed-by: kcr, jhendrikx
1 parent fbcbc98 commit cf55984

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed
 

‎modules/javafx.controls/src/main/java/javafx/scene/control/skin/ScrollPaneSkin.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -294,6 +294,7 @@ public ScrollPaneSkin(final ScrollPane control) {
294294
() -> {
295295
getSkinnable().requestLayout();
296296
viewRect.requestLayout();
297+
viewContent.requestLayout();
297298
},
298299
control.fitToWidthProperty(),
299300
control.fitToHeightProperty()

‎modules/javafx.controls/src/test/java/test/javafx/scene/control/skin/ScrollPaneSkinTest.java

+61
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,67 @@ public void setup() {
144144
assertTrue(originalValue < scrollPane.getVvalue());
145145
}
146146

147+
@Test
148+
public void fitToHeight() {
149+
StackPane content = new StackPane();
150+
content.setPrefWidth(100);
151+
content.setPrefHeight(100);
152+
153+
scrollPane.setContent(content);
154+
scrollPane.setPrefWidth(200);
155+
scrollPane.setPrefHeight(200);
156+
scrollPane.setFitToHeight(false);
157+
158+
Scene scene = new Scene(new Group(), 400, 400);
159+
((Group) scene.getRoot()).getChildren().clear();
160+
((Group) scene.getRoot()).getChildren().add(scrollPane);
161+
Stage stage = new Stage();
162+
stage.setScene(scene);
163+
stage.show();
164+
165+
assertTrue(content.getHeight() == 100);
166+
167+
scrollPane.setFitToHeight(true);
168+
Toolkit.getToolkit().firePulse();
169+
170+
assertTrue(content.getHeight() > 150);
171+
172+
scrollPane.setFitToHeight(false);
173+
Toolkit.getToolkit().firePulse();
174+
175+
assertTrue(content.getHeight() == 100);
176+
}
177+
178+
@Test
179+
public void fitToWidth() {
180+
StackPane content = new StackPane();
181+
content.setPrefWidth(100);
182+
content.setPrefHeight(100);
183+
184+
scrollPane.setContent(content);
185+
scrollPane.setPrefWidth(200);
186+
scrollPane.setPrefHeight(200);
187+
scrollPane.setFitToWidth(false);
188+
189+
Scene scene = new Scene(new Group(), 400, 400);
190+
((Group) scene.getRoot()).getChildren().clear();
191+
((Group) scene.getRoot()).getChildren().add(scrollPane);
192+
Stage stage = new Stage();
193+
stage.setScene(scene);
194+
stage.show();
195+
196+
assertTrue(content.getWidth() == 100);
197+
198+
scrollPane.setFitToWidth(true);
199+
Toolkit.getToolkit().firePulse();
200+
201+
assertTrue(content.getWidth() > 150);
202+
203+
scrollPane.setFitToWidth(false);
204+
Toolkit.getToolkit().firePulse();
205+
206+
assertTrue(content.getWidth() == 100);
207+
}
147208

148209
boolean continueTest;
149210
class myPane extends Pane {

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Oct 11, 2024

@openjdk-notifier[bot]
Please sign in to comment.