6 Replies Latest reply: Oct 23, 2013 12:04 PM by TranQuocUng

calculate position Horizontal ScrollBar Thumb

Assuming as having a width 100 and a visible area of 50 width

how to move the thumb of the scrollbar based on 70 position.

there is a method setValue (??), but how do I calculate the position
correct regarding 70 so that the thumb moves in proportion
correct??

thank's

• 1. Re: calculate position Horizontal ScrollBar Thumb

It's not clear why you would want to do this (you should really only deal with the data, not the implementation details of how the scroll bar is painted).

It would seem reasonable to assume the following relationships hold, though:

value / ( max - min ) = position / (width - visibleWidth)

and

visibleAmount / (max - min) = visibleWidth / width

where position, visibleWidth, and width are in graphical units (pixels), and min, max, value, and visibleAmount refer to the properties defined by ScrollBar.

Some simple algebra should give you the value in terms of quantities you either know or can query the scrollbar for.

• 2. Re: calculate position Horizontal ScrollBar Thumb

thanks for the reply, it is a word processing program, like that of netbeans, extended the listview for it, and when to typing requires that the thumb is positioned correctly in relation to the cursor position within the component.

• 3. Re: calculate position Horizontal ScrollBar Thumb

Doesn't just setting the scrollbar values directly work? I.e., for your example

```scrollbar.setMin(0);
scrollbar.setMax(100);
scrollBar.setVisibleAmount(50);
scrollbar.setValue(70);
```
• 4. Re: calculate position Horizontal ScrollBar Thumb

ok, I will test your suggestion, thanks James_D.

• 5. Re: calculate position Horizontal ScrollBar Thumb

listView inside a horizontal scrollBar is correct, but
Vertical in scrollBar not do it correctly.

I did the following test for scrollBar vertical

scrollbarVertical.setMin(0);

scrollbarVertical.setMax(100);

scrollbarVertical.setVisibleAmount(50);

scrollbarVertical.setValue(70);  <--   no set correct

internally work with values between 0 and 1   and after these settings the setValue no set correct thumb.

is a bug or lack some understanding of this implementation?

• 6. Re: calculate position Horizontal ScrollBar Thumb

Hi,

It's seems like as my problem How to auto-scroll  to the end in WebView ? ==>  https://forums.oracle.com/thread/2595743

On the WebView, I can't set value for scrollbar in the webview.

Thanks.