在 ScrollPane 上滚动时,当我到达底部时,它会留下很多空白空间,我希望对此进行限制,以便当 ScrollPane 的底部元素可见时它停止允许滚动。
正如您所看到的,底部有很多空间,理想情况下,在“TestIdleLevel2”可见后将无法滚动。
滚动 Pane :
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 左右。
最佳答案
问题:itemCollection 被初始化为与 shopInterface 相同的大小。
解决方案:将高度初始化为shopInterface的较小实例。 (在本例中,确切的金额是 shopInterface.getHeight()/4)。
特别感谢法比安。
关于java - 如何限制ScrollPane的滚动量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50690467/