ADDITIONAL SYSTEM INFORMATION :
Linux 4.18.0-305.10.2.el8_4.x86_64 #1 SMP Tue Jul 20 20:34:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
openjdk version "11.0.11" 2021-04-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.11+9-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.11+9-LTS, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
We have a ScrollPane placed in a Window. Every time the ScrollPane's contents are updated, we call Window#sizeToScene to make the window fit to its contents. Once the Window's maximum height has been reached/exceeded, we expect the ScrollPane's scrollbars to show up. However, they are not visible until the window is moved or resized.
If desired, screenshots or a short video can be provided.
Note: Demo application reproduces the problem for the vertical scrollbar. I did not check if the problem also occurs for the horizontal scrollbar alone, but I assume that it does.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
* Start provided test application
* Add some labels to the dialog by using the button in the main window until the dialog window reaches its max height
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Once dialog window has reached its max height, the scrollbars around the dialog content should be visible
ACTUAL -
Once dialog window has reached its max height, the scrollbars around the dialog content are (most of the time) not visible. (Rarely, they are visible - when another label is added to the dialog, they usually vanish again.)
If the dialog window is moved or resized, the expected scrollbars show up.
---------- BEGIN SOURCE ----------
package fx;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;
public class StageScrollPaneIssuesApp extends Application {
private final Stage dialogWindow = new Stage(StageStyle.UTILITY);
private int labelCount = 0;
@Override
public void start(final Stage stage) throws Exception {
final VBox vbox = new VBox();
addLabel(vbox);
final ScrollPane scrollPane = new ScrollPane(vbox);
final StackPane dialogRoot = new StackPane(scrollPane);
dialogWindow.setScene(new Scene(dialogRoot));
dialogWindow.setMaxHeight(200);
final Button addToDialogButton = new Button("Add to dialog");
addToDialogButton.setOnAction(evt -> {
addLabel(vbox);
/*
* For both options below, scrollbars are not visible until dialog window moved or resized.
* It starts working once you apply the WORKAROUND in #sizeToScene in both cases.
*/
sizeToScene(dialogWindow);
// Platform.runLater(() -> sizeToScene(dialogWindow));
});
dialogWindow.getScene().heightProperty().addListener((obs, oldH, newH) -> {
System.out.println("Dialog window scene height changed: " + oldH + " -> " + newH);
});
final StackPane mainRoot = new StackPane(addToDialogButton);
final Scene scene = new Scene(mainRoot);
stage.setTitle("Demo ScrollPane in Dialog & sizeToScene");
stage.setScene(scene);
stage.sizeToScene();
stage.show();
dialogWindow.setTitle("Dialog");
dialogWindow.initOwner(stage);
dialogWindow.sizeToScene();
dialogWindow.setX(stage.getX() + 150);
dialogWindow.setY(stage.getY());
dialogWindow.show();
}
private void addLabel(final Pane parent) {
parent.getChildren().add(new Label(String.format("This is Label %05d", labelCount++)));
}
private static void sizeToScene(final Window dialogWindow) {
dialogWindow.sizeToScene();
/*
* WORKAROUND: it mysteriously starts working when you set the x value again!
* (scrollbars flicker, but at least they are visible.)
*/
// dialogWindow.setX(dialogWindow.getX());
}
public static void main(final String[] args) {
StageScrollPaneIssuesApp.launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
As demonstrated in the test application: If the dialog's window position #setX method is called, even with an unchanged X value, the scroll bars show up (but flicker).
FREQUENCY : often
Linux 4.18.0-305.10.2.el8_4.x86_64 #1 SMP Tue Jul 20 20:34:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
openjdk version "11.0.11" 2021-04-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.11+9-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.11+9-LTS, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
We have a ScrollPane placed in a Window. Every time the ScrollPane's contents are updated, we call Window#sizeToScene to make the window fit to its contents. Once the Window's maximum height has been reached/exceeded, we expect the ScrollPane's scrollbars to show up. However, they are not visible until the window is moved or resized.
If desired, screenshots or a short video can be provided.
Note: Demo application reproduces the problem for the vertical scrollbar. I did not check if the problem also occurs for the horizontal scrollbar alone, but I assume that it does.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
* Start provided test application
* Add some labels to the dialog by using the button in the main window until the dialog window reaches its max height
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Once dialog window has reached its max height, the scrollbars around the dialog content should be visible
ACTUAL -
Once dialog window has reached its max height, the scrollbars around the dialog content are (most of the time) not visible. (Rarely, they are visible - when another label is added to the dialog, they usually vanish again.)
If the dialog window is moved or resized, the expected scrollbars show up.
---------- BEGIN SOURCE ----------
package fx;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;
public class StageScrollPaneIssuesApp extends Application {
private final Stage dialogWindow = new Stage(StageStyle.UTILITY);
private int labelCount = 0;
@Override
public void start(final Stage stage) throws Exception {
final VBox vbox = new VBox();
addLabel(vbox);
final ScrollPane scrollPane = new ScrollPane(vbox);
final StackPane dialogRoot = new StackPane(scrollPane);
dialogWindow.setScene(new Scene(dialogRoot));
dialogWindow.setMaxHeight(200);
final Button addToDialogButton = new Button("Add to dialog");
addToDialogButton.setOnAction(evt -> {
addLabel(vbox);
/*
* For both options below, scrollbars are not visible until dialog window moved or resized.
* It starts working once you apply the WORKAROUND in #sizeToScene in both cases.
*/
sizeToScene(dialogWindow);
// Platform.runLater(() -> sizeToScene(dialogWindow));
});
dialogWindow.getScene().heightProperty().addListener((obs, oldH, newH) -> {
System.out.println("Dialog window scene height changed: " + oldH + " -> " + newH);
});
final StackPane mainRoot = new StackPane(addToDialogButton);
final Scene scene = new Scene(mainRoot);
stage.setTitle("Demo ScrollPane in Dialog & sizeToScene");
stage.setScene(scene);
stage.sizeToScene();
stage.show();
dialogWindow.setTitle("Dialog");
dialogWindow.initOwner(stage);
dialogWindow.sizeToScene();
dialogWindow.setX(stage.getX() + 150);
dialogWindow.setY(stage.getY());
dialogWindow.show();
}
private void addLabel(final Pane parent) {
parent.getChildren().add(new Label(String.format("This is Label %05d", labelCount++)));
}
private static void sizeToScene(final Window dialogWindow) {
dialogWindow.sizeToScene();
/*
* WORKAROUND: it mysteriously starts working when you set the x value again!
* (scrollbars flicker, but at least they are visible.)
*/
// dialogWindow.setX(dialogWindow.getX());
}
public static void main(final String[] args) {
StageScrollPaneIssuesApp.launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
As demonstrated in the test application: If the dialog's window position #setX method is called, even with an unchanged X value, the scroll bars show up (but flicker).
FREQUENCY : often