Skip to content
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

Replaced bindBidirectional calls by a pair of ChangeListener to bind scrollbar coordinates and content position. #98

Merged
merged 1 commit into from
Aug 25, 2021

Conversation

fthevenet
Copy link
Contributor

This PR addresses issue #97

It replaces bindBidirectional calls by a pair of ChangeListener to bind scrollbar coordinates and content position.
This is needed because original solution no longer works after https://bugs.openjdk.java.net/browse/JDK-8264770

…scrollbar coordinates and content position.

This is needed because original solution  no longer works after https://bugs.openjdk.java.net/browse/JDK-8264770
@Jugen
Copy link
Contributor

Jugen commented Aug 25, 2021

Thank you very much for reporting, researching, and PR submission !!!

@Jugen Jugen merged commit 713bc6c into FXMisc:master Aug 25, 2021
Bindings.bindBidirectional(hbarValue, hPosEstimate);
Bindings.bindBidirectional(vbarValue, vPosEstimate);
hbarValue.addListener((observable, oldValue, newValue) -> hPosEstimate.setValue(newValue));
hPosEstimate.addListener((observable, oldValue, newValue) -> hbarValue.setValue(newValue));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the object referenced by hPosEstimate is eligible for garbage collection once the variable goes out of scope. The bidirectional binding will not make the object strongly reachable, since bidirectional bindings in JavaFX use weak listeners (and have always done so).

The new code captures a reference to hPosEstimate and strongly references it from the listener of hbarValue, which itself is strongly referenced. This is probably why it works, and why the original doesn't (and should never have, so there's the question why it once worked in the first place).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this, @mstr2

Following your remark, I did a quick test reverting all my previous change and instead declaring hPosEstimate and vPosEstimate as final members of the class to capture a strong ref to these.

It did not, however, have the expected behavior (i.e. scoll bar was broken, as with the original code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants