如何限制ScrollPane的滚动量

时间:2018-06-05 00:31:10

标签: java css javafx scrollpane

在我的ScrollPane上滚动时,当我到达底部时会留下很多空白空间,我希望它受到限制,以便当ScrollPane的底部项目变为可见时停止允许滚动。

图片1 - ScrollPane的顶部 Image 1, top of the ScrollPane

图片2 - ScrollPane中途 Image 2, top of the ScrollPane

正如您所看到的那样,底部有很多空间,理想情况下,在“TestIdleLevel2”变为可见之后,这将停止滚动。

的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());

转换其中的项目:

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

每个变换由一个计数器分隔,以将其分隔出来,这在物品循环通过(4)后停止。 首选高度设置为大约300,并且由于ScrollPane应该扩展到大约400。但是,ScrollPane将其扩展到大约500-600。

1 个答案:

答案 0 :(得分:0)

问题:itemCollection正在初始化为与shopInterface相同的大小。

解决方案:将高度初始化为shopInterface的较小实例。 (在这种情况下,确切的金额是shopInterface.getHeight()/ 4)。

特别感谢Fabian。