Issue
i has been trying to get value getVisibleAmount() from ScrollPane, which ScrollPane has a child AnchorPane and ScrollBar. in this case i want to get ScrollBar child from ScrollPane to getVisibleAmount() function. where this function only on ScrollBar component.
i want applying getVisibleAmount() from ScrollPane child(ScrollBar) to different ScrollBar separately.
i'm sorry my english it's not really good, maybe this picture can helping what i'm trying to achieve.
Any solution will be appreciated. thank you.
Solution
Here is a method to get the visible amount from a ScrollPane
's ScrollBar
:
static double getScrollBarVisibleAmount(ScrollPane scrollPane, Orientation orientation) {
for (Node node : scrollPane.lookupAll(".scroll-bar")) {
if (node instanceof ScrollBar) {
ScrollBar scrollBar = (ScrollBar) node;
if (scrollBar.getOrientation() == orientation) {
return scrollBar.getVisibleAmount();
}
}
}
return -1.0;
}
You can use it like this:
double amount = getScrollBarVisibleAmount(myScrollPane, Orientation.VERTICAL);
You need to know exactly when to call this method as the ScrollPane
might not have been shown at the time of calling. It also will be easier to track the changes if you assign a ChangeListener<Number>
:
scrollBar.visibleAmountProperty().addListener((observable, oldValue, newValue) -> System.out.println("New visible amount: " + newValue));
Answered By - Miss Chanandler Bong