0
A
回答
2
您可以使用綁定基於滾動條位置來調整這個特殊對象的位置,看下代碼:
public class FancyScrollPane extends Application {
@Override
public void start(Stage primaryStage) {
ScrollPane scrollPane = new ScrollPane();
Pane content = new Pane();
scrollPane.setContent(content);
// adding background
content.getChildren().add(new Rectangle(500, 500, Color.GREEN));
Circle immovableObject = new Circle(30, Color.RED);
content.getChildren().add(immovableObject);
primaryStage.setScene(new Scene(scrollPane, 300, 300));
primaryStage.show();
// here we bind circle Y position
immovableObject.layoutYProperty().bind(
// to vertical scroll shift (which ranges from 0 to 1)
scrollPane.vvalueProperty()
// multiplied by (scrollableAreaHeight - visibleViewportHeight)
.multiply(
content.heightProperty()
.subtract(
new ScrollPaneViewPortHeightBinding(scrollPane))));
}
// we need this class because Bounds object doesn't support binding
private static class ScrollPaneViewPortHeightBinding extends DoubleBinding {
private final ScrollPane root;
public ScrollPaneViewPortHeightBinding(ScrollPane root) {
this.root = root;
super.bind(root.viewportBoundsProperty());
}
@Override
protected double computeValue() {
return root.getViewportBounds().getHeight();
}
}
public static void main(String[] args) { launch(); }
}
相關問題
- 1. 如何在滾動時始終可見節點?
- 2. 滾動條始終在CollapsiblePanelExtender中可見
- 3. 始終可見的水平滾動條
- 4. webkit2png.py - 滾動條始終可見
- 5. 使主滾動條始終可見
- 6. 垂直嵌套滾動始終可見
- 7. 在網站上滾動時窗口始終可見?
- 8. 使主滾動條始終可見 - 無需滾動
- 9. 使滾動條始終在div中可見 - 鉻合
- 10. 如何使滾動條在QML中的Flckable上始終可見
- 11. 如何使jScrollPane自定義滾動條始終可見?
- 12. 移動列表視圖過濾器在滾動時始終可見
- 13. 可滾動表保持標題始終可見
- 14. 始終可見qml
- 15. DataGrid - 如何使兩個滾動條始終可見?
- 16. 如何讓listview的滾動條始終可見
- 17. 爲什麼垂直滾動條始終可見
- 18. 無法讓微調器的滾動條始終可見(Android)
- 19. 當錨點點擊時滾動div 30px
- 20. 如何使div滾動條始終可見?
- 21. 的Java FX「從類型節點setDisabled(布爾)的方法是不可見的」
- 22. 滾動到不可預知的錨點
- 23. DatePicker/Timepicker始終可見
- 24. JQuery滾動到點擊錨定?
- 25. HTML錨點擊時的滾動位置
- 26. 如何使UIScrollView始終可滾動
- 27. 如何始終使UIScrollView可滾動?
- 28. 可見和不可見按鈕時點擊+相同的滾動在ScrollView ios
- 29. 多次滾動到錨點
- 30. Java FX - 如何終止ScheduledService