Search code examples
javaswinguser-interfacenetbeans-8

How to exceed the scroll bar beyond the scroll pane in a GUI application


I am designing a online marketing page on GUI(user interface). I have added a scroll pane in my main JFrame. The scroll pane starts from 'vertical position = 20' and so does the scroll bar during run time. I want the scroll bar to start from 'vertical position = 0' instead of 20, with the scroll pane still remaining at 'verticle position = 20'

I've tried changing the maximum and minimum size in the properties, but it doesn't work.


Solution

  • A simple example would help in understanding your issue. In the meantime, try to use the following method in JComponent. This works with the component's viewport ancestor, if it has one, and moves the viewport so the given rectangle area is visible or at least its origin. In your case, you could add the component to view to the scrollPane and then call component.scrollRectToVisible(startRect) to ensure the starting position is correct.

    public void scrollRectToVisible(Rectangle rect)