如何限制滚动 ScrollPane 的数量
How to limit the amount of scrolling ScrollPane does
在我的 ScrollPane 上滚动时,当我到达底部时它会留下很多空白 space,我希望对其进行限制,以便在 ScrollPane 的底部项目可见时停止滚动。
图片 1 - 滚动窗格顶部
图 2 - ScrollPane 的中途
如您所见,底部有很多 space,理想情况下,这将在 "TestIdleLevel2" 可见后停止滚动。
滚动窗格:
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);
每个转换都由一个计数器分隔,以 space 它出来,在项目循环通过 (4) 后停止。
首选高度设置为大约 300,并且由于 ScrollPane 的缘故应该扩展到大约 400。但是,ScrollPane 将其扩展到 500-600 左右。
问题:itemCollection 被初始化为与 shopInterface 相同的大小。
解决方案:将高度初始化为较小的shopInterface 实例。 (在这种情况下,确切的数量是 shopInterface.getHeight()/4)。
特别感谢 Fabian。
在我的 ScrollPane 上滚动时,当我到达底部时它会留下很多空白 space,我希望对其进行限制,以便在 ScrollPane 的底部项目可见时停止滚动。
图片 1 - 滚动窗格顶部
图 2 - ScrollPane 的中途
如您所见,底部有很多 space,理想情况下,这将在 "TestIdleLevel2" 可见后停止滚动。
滚动窗格:
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);
每个转换都由一个计数器分隔,以 space 它出来,在项目循环通过 (4) 后停止。 首选高度设置为大约 300,并且由于 ScrollPane 的缘故应该扩展到大约 400。但是,ScrollPane 将其扩展到 500-600 左右。
问题:itemCollection 被初始化为与 shopInterface 相同的大小。
解决方案:将高度初始化为较小的shopInterface 实例。 (在这种情况下,确切的数量是 shopInterface.getHeight()/4)。
特别感谢 Fabian。