[英]How to limit the amount of scrolling ScrollPane does
在ScrollPane上滚动时,当我到达底部时会留下很多空白,我希望对此进行限制,以便在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左右。
问题:itemCollection被初始化为与shopInterface相同的大小。
解决方案:将高度初始化为shopInterface的较小实例。 (在这种情况下,确切的金额是shopInterface.getHeight()/ 4)。
特别感谢Fabian。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.