Make java scroll bar in middle of scrollable content

I have a horizontal scrollbar that controls a large panel (with a very large width and very small height, so a horizontal panel).

I want to start the scroll bar (when the handle is on the max. To the left) DO NOT start from the beginning of the panel, it scrolls, but rather in a certain place that I dictate. The same goes for the end of the scroll bar (when the knob is at max right).

I found that the scroll bar is always tied to the panel that it scrolls, and I cannot figure out how to change its behavior.

EDIT:

As an example, imagine a regular web page: when at the top of the page, the scroll bar handle is also at the top. When down, the scroll bar knob is down. I want to define new restrictions for the content, so that when the scroll bar knob reaches the top or bottom, the page displays the limit that I defined, instead of the real top and bottom.

+4
source share
3 answers

I solved the problem using the JScrollbar setValues() method, which allows me to set the maximum, minimum, value and size of the scroll bar at the same time . By setting the maximum and minimum values โ€‹โ€‹that I want, the scroll bar behaves the way I wanted / expected.

The problem was that I set only the maximum and minimum values โ€‹โ€‹( setMaximum , setMinimum ), and since there is a strict policy on the model, the minimum <= value <= value + degree <= maximum that estrategy does not work.

+3
source

As shown in How to use the scrollbars , you can use the scrollRectToVisible() component to scroll to an arbitrary Rectangle . Here is an example here .

Application: like Container , a JPanel is fairly interchangeable, even if it has significant embedded content. One reliable way to share content at a given level is CardLayout , shown here , here and here .

+3
source

Is it possible to save a large panel as backup storage and copy the area of โ€‹โ€‹interest to the panel, which is actually implemented in scrollpane. This way you don't have to contend with scroll behavior.

+2
source

Source: https://habr.com/ru/post/1394049/


All Articles