Search code examples
javaswingjscrollpane

How do I anchor my Horizontal Scrollbar to the top of the JScrollPane


I would like to move the Horizontal scroll bar to the top of my JScrollPane. Does anyone knows how to do this ? I am on Java swing.


Solution

  • Start by reading the JScrollPane API.

    At the right of the first page you will see a simple diagram showing the layout of the scroll pane. You will see:

    1. positions for the horizontal (and vertical) scrollbars
    2. a location titled the "column header"

    So what you need to do is move the horizontal scrollbar to the column header. To this you need to:

    1. get a reference to the horizontal scrollbar. Read the API for the appropriate "getter" method
    2. set the scrollbar to the column header. Read the API for the appropriate "setter" method.