Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ScrollPane fill width and preferred size

zonskiNov 9 2011 — edited Jul 31 2012
I suspect this is going to end up as a feature request, but does anyone know if there is an existing way to have a ScrollPane stretch its content if the available space is greater than the preferred size of the content, but also not shrink the content if the scrollpane is smaller than the preferred size of the content?

If we have this simple example:
public void start(Stage stage) throws Exception
{
    BorderPane contentPane = new BorderPane();
    contentPane.setPrefSize(400, 300);
    contentPane.setStyle("-fx-background-color: blue");
 
    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setContent(contentPane);

    Scene scene = new Scene(scrollPane, 800, 600);
    stage.setScene(scene);
    stage.show();
}
When the window is big, our content pane is left at its preferred size with white space around it and no scroll bars showing. When the window is small our contentPane is still at its preferred size with scrollbars on it and no white space. Much as we'd expect.

If we add this line of code:
scrollPane.setFitToWidth(true);
Then when the window is big then our contentPane is stretched nicely to fill the available space. When the window is small, the scroll bars don't kick-in (effectively scrolling is turned off) and the contentPane is shrunk to fit the available space.

What I'd rather have is when the window is small we get scrolling, when the window is big, we get stretching. Possible?

Cheers,
zonski
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 28 2012
Added on Nov 9 2011
6 comments
1,439 views