JavaFX-如何同步TextArea滚动条和ScrollPane滚动条 [英] JavaFX - How to sync up TextArea scroll bar and ScrollPane scroll bar
问题描述
我有一个TextArea
元素,它本身有一个滚动条,还有一个单独的ScrollPane
,有一个滚动条.如何使其中一个滚动条与另一个滚动条相匹配?
I have a TextArea
element which itself has a scroll bar and a separate ScrollPane
which has a scroll bar. How can i make one of the scroll bars match their position with the other one?
我一直在寻找获取滚动条位置的方法.
I have been looking up methods for acquiring the position of a scroll bar.
对于ScrollPane
,有一个.getVvalue()
会返回一个从0到1的双精度值.基本上像sort的百分比值.
For ScrollPane
there is .getVvalue()
which returns a double from 0 to 1. Basically like a percentage value of sort.
对于TextArea
,还有一个.getScrollTop()
也会返回一个double,但是除非您手动向下滚动该条以找出最底部的位置,否则最大值几乎是未知的.
For TextArea
there's .getScrollTop()
which also returns a double but it's maximum value is unknown pretty much unless you manually scroll the bar down to find out the position at the very bottom.
由于它们都返回不同的值,所以我必须知道它们的最大位置.
Since they both return different values I would have to know the maximum position for both of them.
推荐答案
TextArea
有一个孩子,即它的ScrollPane
.因此,百分比滚动可以找到为
A TextArea
has one child, which is its ScrollPane
. The percentage scroll can therefore be found as
((ScrollPane) textArea.getChildrenUnmodifiable().get(0)).getVvalue()
希望这会有所帮助!
这篇关于JavaFX-如何同步TextArea滚动条和ScrollPane滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!