1

When scrolling on my ScrollPane, it leaves a lot of empty space when I reach the bottom, I want this to be limited so it stops allowing scrolling when the bottom item of the ScrollPane becomes visible.

Image 1 - Top of the ScrollPane Image 1, top of the ScrollPane

Image 2 - Midway down the ScrollPane Image 2, top of the ScrollPane

As you can see there's a lot of space at the bottom, ideally this would stop being able to scroll after "TestIdleLevel2" becomes visible.

ScrollPane:

ScrollPane itemCollectionScrollPane = new ScrollPane(itemCollection);
    itemCollectionScrollPane.setPrefSize(shopInterface.getPrefWidth()*1.55, shopInterface.getPrefHeight());
    itemCollectionScrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
    itemCollectionScrollPane.getStylesheets().add(Shop.class.getResource("/cssFolder/TransparentScrollPane.css").toExternalForm());

Transforms for the items within it:

itemBox.getTransforms().add(new Translate(shopInterface.getTranslateX() - itemBox.getPrefWidth() / 8,
                shopInterface.getTranslateY() + (counter * shopInterface.getPrefHeight() / 3), 0));
        itemCollection.getChildren().addAll(itemBox);

Each transform is separated by a counter to space it out, this stops after the items have been looped through (4). The preferred height is set to about 300, and should be extended to about 400 due to the ScrollPane. However, the ScrollPane is extending it to around 500-600.

Cœur
  • 37,241
  • 25
  • 195
  • 267
User123456
  • 69
  • 8
  • 1
    A `ScrollPane` uses the size of it's content to set up the scrollbar ranges. This means `itemCollection`'s size is larger. Since you didn't add enough info to see what `itemCollection` is or how it's filled, we cannot really help you with this. BTW: for most parents transforms won't be considered when determining the bounds. – fabian Jun 05 '18 at 07:26
  • @fabian You were quite right, I was initializing the itemCollection size to be the same as the pane it was stored within, in this case I needed the width to be set to around half the size, thank you :) – User123456 Jun 05 '18 at 08:21

1 Answers1

0

Issue: itemCollection was being initialized as the same size as shopInterface.

Solution: Initialize the height as a smaller instance of shopInterface. (In this case the exact amount was shopInterface.getHeight()/4).

Special thanks to Fabian.

User123456
  • 69
  • 8