-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get ScrollPane vertical positions? #1108
Comments
You can try the following: scroll.estimatedScrollYProperty().addListener
(
// Need runLater otherwise getTotalHeightEstimate sometimes reports
// NullPointerException when setting the text area with text ?
y -> Platform.runLater( () ->
{
double currentAbsolutePos = ((Var<Double>) y).getValue();
double totalEstimatedHeight = scroll.getTotalHeightEstimate();
double viewPortHeight = scroll.getHeight();
double fractionalPos = currentAbsolutePos / (totalEstimatedHeight - viewPortHeight);
if ( fractionalPos == 0.0 )
{
System.out.println( "top" );
}
else if ( fractionalPos >= 1 )
{
System.out.println( "bottom" );
}
}
)); |
@Jugen Thank you for your solution. The only problem - I don't like |
@Jugen Getting scroll position is one of the most used features (for example, someElement.scrollTop is used very often in JS), so it will be always necessary to have a solid solution. |
Please try and leave out the |
Your solution seems to work (I get
I need to get scroll position in a window that shows log information. Nobody can paste there text (I mean Ctrl+V) manually, but automatically added text can be rather large. |
Okay here is a better version that doesn't have the NPE problem: scroll.estimatedScrollYProperty().addListener( (ob,ov,currentAbsolutePos) ->
{
double viewPortHeight = scroll.getHeight();
double totalEstimatedHeight = (double) scroll.totalHeightEstimateProperty().getOrSupply( () -> 1.0 );
double fractionalPos = (double) currentAbsolutePos / (totalEstimatedHeight - viewPortHeight);
if ( fractionalPos == 0.0 )
{
System.out.println( "top" );
}
else if ( fractionalPos >= 1 )
{
System.out.println( "bottom" );
}
}); |
@Jugen Thank you very much for your help. You solution seems to be OK, but once I got |
Yes, sometimes I get fractionalPos = 0.9999......, maybe the problem is that when I scroll to bottom this way:
there is 1 or 2 pixels left to bottom. I mean, I can't scroll to real bottom using code. So, when I check if it is a bottom, I get |
So maybe try either |
@Jugen Yes, thank you. This is the way I went. |
I have a TextArea and a ScrollPane:
And I need to know when my vertical bar is at the highest and the lowest positions. By other words when vertical scroll bar is on top or bottom. Something like this:
I've found several issues related to this problem but still have no solution. Could anyone say how to do it?
The text was updated successfully, but these errors were encountered: